解决Kafka消费端错误:o.s.kafka.listener.LoggingErrorHandler : Error while processing: null

简单记录下使用kafka遇到的问题,万一也会有小伙伴遇到了呢。

程序端使用springboot服务消费kafka,某天出现消息大量堆积,经过定位到错误日志如下:

2020-05-12 10:22:36.500 ERROR 5171 --- [org.springframework.kafka.KafkaListenerEndpointContainer#0-0-C-1] o.s.kafka.listener.LoggingErrorHandler   : Error while processing: null

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.
	at org.apache.kafka.clients.consumer.internals.ConsumerCoordinator.sendOffsetCommitRequest(ConsumerCoordinator.java:808)
	at org.apache.kafka.clients.consumer.internals.ConsumerCoordinator.commitOffsetsSync(ConsumerCoordinator.java:691)
	at org.apache.kafka.clients.consumer.KafkaConsumer.commitSync(KafkaConsumer.java:1416)
	at org.apache.kafka.clients.consumer.KafkaConsumer.commitSync(KafkaConsumer.java:1377)
	at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.commitIfNecessary(KafkaMessageListenerContainer.java:1466)
	at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.processCommits(KafkaMessageListenerContainer.java:1330)
	at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.pollAndInvoke(KafkaMessageListenerContainer.java:715)
	at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.run(KafkaMessageListenerContainer.java:676)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.lang.Thread.run(Thread.java:748)

大致意思就是:偏移量无法提交,因为已经发生了再均衡将分区分配给了另一个消费者线程,poll循环花费了太多时间处理消息。意思其实非常明显了,就是单条消息的处理逻辑太耗时,超过了max.poll.interval.ms。max.poll.interval.ms我们使用的是默认值,稍稍定位代码发现我们消费端处理消息的逻辑中有个写elasticsearch(记录/监控功能)的操作,于是加入日志定位下这个操作所耗费时间,发现……,然后去掉这个es写入操作,堆积的消息消费大大加快……

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页