What is the difference between advertised.listeners and bootstrap.servers?

Viewed 2846

I want to configure kafka so client can connect to it. What is the difference between advertised.listeners and bootstrap.servers in kafka configuration?

2 Answers

bootstrap.servers parameter is used only for initial connection to cluster. After this initial connection is established, Kafka returns advertised.listeners which is ip/port list that is used to connect to broker(s).

This image can be helpful to understand the concept:

enter image description here

Note: advertised.host.name is deprecated, you can assume that as advertised.listeners

For more information you can check Kafka docs:

bootstrap.servers: A list of host/port pairs to use for establishing the initial connection to the Kafka cluster. The client will make use of all servers irrespective of which servers are specified here for bootstrapping—this list only impacts the initial hosts used to discover the full set of servers. This list should be in the form host1:port1,host2:port2,.... Since these servers are just used for the initial connection to discover the full cluster membership (which may change dynamically), this list need not contain the full set of servers (you may want more than one, though, in case a server is down).

advertised.listeners: Listeners to publish to ZooKeeper for clients to use, if different than the listeners config property. In IaaS environments, this may need to be different from the interface to which the broker binds. If this is not set, the value for listeners will be used. Unlike listeners it is not valid to advertise the 0.0.0.0 meta-address.

Reference for image: https://www.udemy.com/course/kafka-cluster-setup/

bootstrap.servers is a list of broker(s) that you provide your client with to connect to the Kafka cluster.

advertised.listeners is the host&port of each broker that the client is provided with on the initial connection to the bootstrap.server. When the client connects to brokers subsequently it will use these and not the bootstrap.server, which is why it is so important that you set advertised.listeners correctly based on your networking setup.

For more details see https://rmoff.net/2018/08/02/kafka-listeners-explained/

Related