'What does multiple KAFKA_ADVERTISED_LISTENERS mean when we have only one broker, vs when we have many?

I am learning Kafka and trying to use it with docker. I'm confused looking at the docker-compose files, so I wanted to ask my questions here.

In most examples, I see a config like this:

broker:
   image: confluentinc/cp-enterprise-kafka:5.3.1
   ...
   ports:
       - "29192:29092" 
       - "9192:9092"
   environment:
        ...
        KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker:29092,PLAINTEXT_HOST://localhost:9092

I wanted to understand a few things related to this:

  1. Is there a particular convention for using 5-digit (ex: 29092) port vs 4-digit (ex: 9092) ports?
  2. Is there a specific relation between the number of configured brokers to the number of listeners mentioned in KAFKA_ADVERTISED_LISTENERS? In some places, like confluent's own example, I see only one broker, but multiple KAFKA_ADVERTISED_LISTENERS. What does that mean?
  3. Also, in the same confluent example mentioned above, there is a listener: PLAINTEXT://broker:29092 in KAFKA_ADVERTISED_LISTENERS, but we do not have any broker or zookeeper configured at port 29092, so what is that doing?


Solution 1:[1]

Is there a particular convention for using 5-digit (ex: 29092) port vs 4-digit (ex: 9092) ports?

To avoid getting a port conflict at run time of an application, you should configure ports for an application out of ephemeral port range of server. Refer this question and answer to find , how can you find or modify the ephemeral port range. So the convention is, find a port out of ephemeral port range and use as an application port.

Is there a specific relation between the number of configured brokers to the number of listeners mentioned in KAFKA_ADVERTISED_LISTENERS? In some places, like confluent's own example, I see only one broker, but multiple KAFKA_ADVERTISED_LISTENERS. What does that mean?

Kafka can be deployed in a cluster within multiple nodes. Each node has its own IP and port number within config/server.properties file. Number of listeners and advertised listeners depends on the number of nodes within your Kafka deployment.

Also, in the same confluent example mentioned above, there is a listener: PLAINTEXT://broker:29092 in KAFKA_ADVERTISED_LISTENERS, but we do not have any broker or zookeeper configured at port 29092, so what is that doing?

Kafka need a Zookeeper deployment to manage its cluster management, irrespective of there is only one node of Kafka or multiple nodes. But it can use any port, and there is no hard and fast rule to use 29092 port.

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 Steephen