生成消息时是否必须指定所有 Kafka broker IP

Do all Kafka broker IPs have to be specified when producing a message

我有 3 个 broker kafka 集群和 3 个 zookeeper。

我的问题是我们是否必须在 producer-console.sh 文件中只提供一个 IP 地址,如下所示

/kafka-console-producer.sh --broker-list 192.168.7.110:9092 --topic test

或者所有三个ip地址

./kafka-console-producer.sh --broker-list 192.168.7.110:9092,192.168.5.110:9092,192.168.3.111:9092 --topic test

如果我只提供一个 IP 来生成消息,并且该 IP 在一段时间后关闭,会发生什么情况。我能否通过该 IP 生成消息,或者我必须提供所有 IP 地址?

查看 Producer config 文档,其中描述了 bootstrap.servers 的用途(bootstrap-servers / broker-list 是同义词):

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).

因此,如果您只提供一个 IP,然后该 IP 被关闭,您的生产者随后将在尝试连接时失败。但是,例如,您可以提供 两个 IP,这样如果一个失败,生产者仍然可以连接到另一个 IP。但是实际消息发送到的代理不受此影响。

also this answer here