Java 客户端配置了单个 Kafka 代理 IP 和连接端口,如果该代理在集群中关闭怎么办

Java client is configured with single Kafka broker IP and port to connect , what if that broker is down in the cluster

我有一个 java 消费者使用 broker1:9092 连接到 kafka 集群(3 个代理)。然后客户端将收到包含集群中代理的元数据,并将连接到其中任何一个。如果 broker1 本身发生故障会发生什么情况,我的消费者使用它来连接并获取元数据信息。我该如何解决这种情况。

我可以将我的 java 消费者指向所有代理 IP 和端口吗?

Can i point my java consumer to all the broker IPs and port ?

是的,你可以做到。实际上,这就是为什么配置名称以“s”结尾的 bootstrap.servers 的原因。

根据 KafkaConsumer 上的 JavaDocs,您可以提供一个 comma-seperated 一个或多个经纪人的列表:

"The connection to the cluster is bootstrapped by specifying a list of one or more brokers to contact using the configuration >bootstrap.servers. This list is just used to discover the rest of the brokers in the cluster and need not be an exhaustive list of servers in the cluster (though you may want to specify more than one in case there are servers down when the client is connecting)."