kafka消费者超时解决方案

本文探讨了Kafka消费者可能出现的消费超时问题,指出这可能导致消息重复消费和集群rebalance。介绍了max.poll.interval.ms和session.timeout.ms的区别,并提供了一些建议来优化配置,如结合业务预估消费能力设置max.poll.records和max.poll.interval.ms,以及将session.timeout.ms设置为heartbeat.interval.ms的三倍。同时澄清了poll中timeout的概念,它指消费者在等待数据时的超时时间,如果超时未获取到数据,则返回空消息。
摘要由CSDN通过智能技术生成

背景

  kafka消费者采用批量拉取的方式,一次拉取一批记录来消费,如果消费者线程消费超时会导致整批消息的回滚,从而导致已经消费过的数据再消费一遍,消费者不幂等会出大问题,这也是为啥要强调使用消费队列一定要考虑幂等性的原因。
  细思极恐的是:这次在规定的时间内消费不完,你能保证下次就能消费完吗?有可能进入拉取-》超时-》回滚-》拉取的无限循环中

消费超时会发生什么?

Kafka Handle Error, Client Will Seek Soon: org.apache.kafka.clients.consumer.CommitFailedException: Commit cannot be completed since the group has already rebalanced and assigned the partitions to another member. This means that the time between subsequent calls to poll() was longer than the configured max.poll.interval.ms, which typically implies that the poll loop is spending too much time message processing. You can address this either by increasing the session timeout or by reducing the maximum size of batches returned in poll() with max.poll.records.

报错信息非常良心,简单解释下:

  • 3
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值