当前位置:   article > 正文

使用Kafka时一定要注意防止消费速度过慢触发rebalance而导致的重复消费_kafka消费者的处理时间慢会造成什么问题

kafka消费者的处理时间慢会造成什么问题

在Java应用中,我们往往会使用spring-kafka组件简单的设置一下group_id, topic就开始消费消息了,其实这样会埋下巨大的安全隐患,即当消费速度过慢时有可能会触发rebalance, 这批消息被分配到另一个消费者,然后新的消费者还会消费过慢,再次rebalance, 这样一直恶性循环下去。发生这种情况最明显的标志就是日志里能看到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.

其实这段话已经很走心了,kafka的开发者已经预料到了这可能是个很容易出现的问题,所以连解决方案都给你列出来了。这里我们需要明确一下,在Kafka 0.10.1.0以后的版本中,影响rebalance触发的参数有三个,说明如下:

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Guff_9hys/article/detail/764296
推荐阅读
相关标签
  

闽ICP备14008679号