当其中一个经纪人关闭时,Kafka 消费者不会收到数据

hum*_*ity 1 apache-kafka


在 RHEL v6.9 上使用 Kafka v2.1.0 的Kafka 快速入门

当 Kafka 代理之一出现故障时,消费者无法接收数据。

执行步骤:
1. 启动zookeeper
2. 启动Kafka-Server0 (localhost:9092, kafkalogs1)
3. 启动Kafka-Server1 (localhost:9094, kafkalog2)
4. 创建topic "test1", num of partitions = 1, replication factor = 2
5. 为主题“test1”运行生产者
6. 运行消费者
7. 从生产者发送消息
8. 在消费者端接收消息。

以上所有步骤都没有任何问题。

当我关闭 Kafka-Server0 时,消费者停止从生产者获取数据。当我重新启动 Kafka-Server0 时,消费者开始从它停止的地方获取消息。

这些是使用的命令

bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test1
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test1
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 2 --partitions 1 --topic test1
Run Code Online (Sandbox Code Playgroud)

当我使用 --bootstrap-server 选项中指定的两个服务器运行消费者时,行为是相同的(消费者端没有收到消息)。

bin/kafka-console-consumer.sh --bootstrap-server localhost:9092,localhost:9094 --topic test1
Run Code Online (Sandbox Code Playgroud)

知道为什么即使主题 test1 的复制因子设置为 2,当 server0 关闭时消费者也停止接收消息吗?

已经有一个类似的问题,但没有完全回答 Kafka 0.10 快速入门:当“主要”代理被关闭时,消费者失败

cri*_*007 5

如果 offsets 主题不可用,则无法消费。

查看server.properties这些文件,并查看上面的注释,并相应增加(仅适用于主题不存在的情况)

# The replication factor for the group metadata internal topics "__consumer_offsets" and "__transaction_state"
# For anything other than development testing, a value greater than 1 is recommended for to ensure availability such as 3.
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
Run Code Online (Sandbox Code Playgroud)

根据你之前的问题,看起来它只有一个副本

了解如何增加现有主题的复制因子