问题描述
Kafka消费者出现偏移量提交异常,报错信息如下:
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.
翻译:由于组已经重新平衡并将分区分配给另一个成员,因此无法完成提交。这意味着后续调用 poll() 之间的时间比配置的 max.poll.interval.ms 长,这通常意味着轮询循环花费了太多时间处理消息。您可以通过增加会话超时或通过使用 max.poll.records 减少 poll() 中返回的批处理的最大大小来解决此问题。
参数max.poll.interval.ms(官网给得默认值为3000)的意思为,当消费者从broker端poll消息时,poll()的调用之间的最大延迟。 这提供了消费者在获取更多记录之前可以空闲的时间量的上限。 如果在此超时到期之前未调用poll(),则认为消费者失效,并且消费者组将重新平衡以便将分区重新分配给其他消费者,消费者处理消息时长 > max.poll.interval.ms值,也就是我们在手动提交的时候,实际上分区信息已经被分配到整个消费者组里面的其它消费者了。
解决方案
-
设置max.poll.interval.ms大于消费者处理消息时长
-
优化消费者处理消息耗时