配置3个broker节点,6个partitions
采用监听消息@KafkaListener(topics = "t1" )
在正常的情况下,发送消息与接受消息是正常的。
模拟故障手工关掉其中一个broker节点时,Consumer接收不到消息,报错org.apache.kafka.clients.NetworkClient - Connection to node 2 could not be established. Broker may not be available.
昵称
0 声望
这家伙太懒,什么都没留下
问题解决了,分区没有副本了,正好在被关的broker上,扩展分区副本数。
配置了这几个参数
offsets.topic.replication.factor=3 transaction.state.log.replication.factor=3 transaction.state.log.min.isr=3
重新调整
consumer_offsets
的Replicas
才会生效,默认是是一对一的Topic: consumer_offsets Partition: 0 Leader: 0 Replicas: 0 Isr: 0
调整后应该是
Topic: __consumer_offsets Partition: 0 Leader: 0 Replicas: 0,1,2 Isr: 0,1,2
调整的命令是:
kafka-reassign-partitions --zookeeper 127.0.0.1:2181 --reassignment-json-file reassign.json --execute
如果是开发环境,可以删掉
zookeeper\kafka
日志重建。补充下,3个broker节点为0、1、2,关掉2节点,Consumer接收不到消息。
Topic:t1 PartitionCount:6 ReplicationFactor:2 Configs: Topic: t1 Partition: 0 Leader: 1 Replicas: 1,2 Isr: 1,2 Topic: t1 Partition: 1 Leader: 2 Replicas: 2,0 Isr: 0,2 Topic: t1 Partition: 2 Leader: 0 Replicas: 0,1 Isr: 0,1 Topic: t1 Partition: 3 Leader: 1 Replicas: 1,2 Isr: 1,2 Topic: t1 Partition: 4 Leader: 2 Replicas: 2,0 Isr: 0,2 Topic: t1 Partition: 5 Leader: 0 Replicas: 0,1 Isr: 0,1
replication配置:
offsets.topic.replication.factor=2 transaction.state.log.replication.factor=2 transaction.state.log.min.isr=2
你的答案