'Should we always have a KAFKA_LISTENERS (inside and outside) specified even if the producer and consumer are on the same n/w?

what if the containers(producer, consumer and kafka) are on the same n/w bridge? I am new to kafka, just trying to run a simple producer and consumer example. I have a docker container which produces messages and pushes it to kafka (this works with by declaring kafka:9092 as a bootstrap server. Since my docker container for kafka is called kafka)

Do i still need to declare inside and outside ports for kafka? Cant the consumer listen to the same port as producer?

Using kafka-python to send and receive messages.



Solution 1:[1]

Consumers and producers don't listen on ports, but as long as you have (at least) PLAINTEXT://kafka:9092 as the advertised listener, and listeners includes port 9092, then you don't necessarily need any other listener.

However, if you add other brokers in the same network for replication, I'd strongly recommend using at least SASL_PLAINTEXT for the inter-broker communication. That way all brokers in the same network "trust" each other as a cluster (and you can fine tune network traffic for replication, but that's not really needed for Docker)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 OneCricketeer