晚上在家打LOL,突然收到线上异常邮件。还好没睡觉,赶紧处理一下。
1.问题
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.
无法完成提交,因为组已重新将分区分配给另一个成员。这意味着对poll()的后续调用之间的时间长于配置的max.poll.interval.ms,这通常意味着poll循环花费了太多时间处理消息。您可以通过增加会话
超时或使用max.poll.records减少poll()中返回的最大批大小来解决此问题。
大概的意思就是消费者创建是的参数设置有点问题。
消费时一次性poll的消息比较多,循环处理耗时较久,超过了默认的等待时长max.poll.interval.ms(默认是3000毫秒),导致触发组重新分配规则。
可以通过增加session会话时间(session.timeout.ms),或者减少每次poll(max.poll.records)数据的数量来解决问题。
2.解决方案
由于我这里用的是jar包方法,方法只提供了max.poll.records参数且默认的为100,无法设置max.poll.interval.ms和session.timeout.ms。所以只能将max.poll.records参数调小一些,来保证数据处理时间降低避免问题。
如果可以自己定义消费者参数的话,可以自己设置合适的参数
有帮助的话,点个赞啊亲!