首页 > 解决方案 > 如果 ID=0 的代理关闭,Kafka 集群将无法工作

问题描述

我有一个带有 3 个代理的 Kafka 集群,配置如下:

Broker-0 : broker.id=0 ; listeners=PLAINTEXT://localhost:9092 ; log.dirs=/opt/data/kafka/logs-0
Broker-1 : broker.id=1 ; listeners=PLAINTEXT://localhost:9093 ; log.dirs=/opt/data/kafka/logs-1
Broker-2 : broker.id=2 ; listeners=PLAINTEXT://localhost:9094 ; log.dirs=/opt/data/kafka/logs-2

生产者以 Broker-2 为目标发布消息

sh-3.2# ./kafka-console-producer.sh --broker-list localhost:9094 --topic clusterTopic

我开始测试所有启动并运行的代理

sh-3.2# ./bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic clusterTopic
Topic:clusterTopic  PartitionCount:1    ReplicationFactor:3 Configs:
Topic: clusterTopic Partition: 0    Leader: 0   Replicas: 0,1,2 Isr: 2,0,1
sh-3.2#

A至此,生产者发布的所有消息都被消费者接收到了

然后我杀了Broker-0(现任领导)

sh-3.2# ./bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic clusterTopic
Topic:clusterTopic  PartitionCount:1    ReplicationFactor:3 Configs:
Topic: clusterTopic Partition: 0    Leader: 1   Replicas: 0,1,2 Isr: 2,1
sh-3.2#

此时,消费者不再收到生产者发布的消息

然后,我启用了 Broker-0

sh-3.2# ./bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic clusterTopic
Topic:clusterTopic  PartitionCount:1    ReplicationFactor:3 Configs:
Topic: clusterTopic Partition: 0    Leader: 1   Replicas: 0,1,2 Isr: 2,1,0
sh-3.2#

此时,生产者发布的所有消息都被消费者正确接收

然后我杀了Broker-1(现任领导)

sh-3.2# ./bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic clusterTopic
Topic:clusterTopic  PartitionCount:1    ReplicationFactor:3 Configs:
Topic: clusterTopic Partition: 0    Leader: 0   Replicas: 0,1,2 Isr: 2,0
sh-3.2#

此时,生产者发布的所有消息仍然被消费者正确接收。

为什么经纪人之间的行为如此不同?

更新 #1

我注意到一些可能有用的东西:

当我杀死 Broker-1 时,我在消费者控制台上看到以下警告(很多次)

[2018-06-07 13:59:00,866] WARN [Consumer clientId=consumer-1, groupId=console-consumer-20882] Connection to node 1 could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)

但是当我杀死 Broker-0 时,我看到了这些警告消息(很多次)

[2018-06-07 14:04:08,433] WARN [Consumer clientId=consumer-1, groupId=console-consumer-20882] Connection to node 2147483647 could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
[2018-06-07 14:04:08,434] WARN [Consumer clientId=consumer-1, groupId=console-consumer-20882] Connection to node 0 could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)

我想知道 ID=2147483647 的经纪人是什么?

标签: apache-kafkaapache-zookeeperkafka-cluster

解决方案


推荐阅读