Kafka日志:

broker 133 received LeaderAndIsrRequest with correlation id 1 from controller 132 epoch 35 fro partition [__consumer_offsets,13] but cannot become follower since the new leader -1 is unavailable

 kafka一个broker挂掉无法写入

this server is not the leader for that topic-partition

 kafka一个broker挂掉无法写入

对于broker 133 received LeaderAndIsrRequest with correlation id 1 from controller 132 epoch 35 fro partition [__consumer_offsets,13] but cannot become follower since the new leader -1 is unavailable

错误是因为

 kafka一个broker挂掉无法写入

因其中一个broker挂掉无法获取leaderbrokerid

3broker中的其中一个挂掉,是可以将数据写入另外两个broker的。至于没有写入另外两个broker报错org.apache.kafka.common.errors.NotLeaderForPartition可能是因为可能我们的producer端的代码里没加 reties 参数,默认就发送一次,遇到leader选举时,找不到leader就会发送失败,造成程序停止

解决办法

producer端加上参数 reties=3, 重试发送三次(默认100ms重试一次 由 retry.backoff.ms控制);
如果还需要保证消息发送的有序性,记得加上参数 max.in.flight.requests.per.connection = 1 限制客户端在单个连接上能够发送的未响应请求的个数,设置此值是1表示kafka broker在响应请求之前client不能再向同一个broker发送请求。(注意:设置此参数是为了满足必须顺序消费的场景,比如binlog数据)

相关文章:

  • 2021-07-17
  • 2022-12-23
  • 2022-12-23
  • 2021-06-18
  • 2021-09-26
  • 2022-12-23
  • 2021-07-08
  • 2021-11-15
猜你喜欢
  • 2022-12-23
  • 2022-01-14
  • 2021-06-08
  • 2021-07-22
  • 2021-08-23
  • 2021-07-17
相关资源
相似解决方案