Kafka listener and advertised.listener

I recently read a blog about kafka listener and advertisedListener,https://www.confluent.io/blog/kafka-listeners-explained/
and found some things that I don’t understand:

KAFKA_LISTENERS: LISTENER_BOB://kafka0:29092,LISTENER_FRED://localhost:9092
KAFKA_ADVERTISED_LISTENERS: LISTENER_BOB://kafka0:29092,LISTENER_FRED://localhost:9092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LISTENER_BOB:PLAINTEXT,LISTENER_FRED:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: LISTENER_BOB
$ kafkacat -b kafka0:9092 \
           -L
Metadata for all topics (from broker -1: kafka0:9092/bootstrap):
1 brokers:
  broker 0 at localhost:9092

kafka bind localhost:9092, but why can access by kafka0:9092?

Hi @fengyinqiao, welcome to the forum :slight_smile:

You’re right that one of the listeners (LISTENER_FRED) is listening on port 9092 on localhost. When we access the broker using 9092 that’s the listener address that’s returned to us.

The reason we can access it as kafka0:9092 is that kafka0 in our example can resolve to the broker from the machine running kafkacat. Probably using this in our example would have been clearer, but the effect is the same:

KAFKA_LISTENERS: LISTENER_BOB://0.0.0.0:29092,LISTENER_FRED://0.0.0.0:9092
2 Likes

Thanks for your warm welcome and reply! :grinning_face_with_smiling_eyes:

Yes, I think in the example, unless you have a host configuration: localhost kafka0, even if kafka0 can resolve to the broker, it still doesn’t work because broker is listening to localhost instead of kafka0.But bind 0.0.0.0, as you said, and that won’t be a problem.So If you have time, could you please modify your blog?

Another question in your blog, when in AWS/IAAS and External address IS resolvable locally ,you give the config:advertised.listeners=PLAINTEXT://ec2-54-191-84-122.us-west-2.compute.amazonaws.com:9092.I want to know if advertised.listener is not required ,and just listeners=PLAINTEXT://ec2-54-191-84-122.us-west-2.compute.amazonaws.com:9092 is enough?

@rmoff might not do it, but Kafka Listeners - Explained is a great article written by Robin.

@rmoff could you please give me a reply when you are free?

I would say go ahead and try it :slight_smile: It’s a while since I wrote the blog, and what I tried and wrote back then was true and accurate. For specific instances like you describe I would work through from the principles described and use them to troubleshoot if it doesn’t work. Advertised listener is fundamentally “what is the host on which this broker can be reached by clients”. I’m not sure what would be gained from trying to shortcut that and specify listeners only.