CommitFailedException Commit cannot be completed since the group has already rebalanced and assigned the partitions to another member

后端 未结 2 435
别那么骄傲
别那么骄傲 2020-12-25 11:23

I was using kafka 0.10.2 and now faced a CommitFailedException. like:

Commit cannot be completed since the group has already rebalanced and assigned

2条回答
  •  眼角桃花
    2020-12-25 11:45

    Hi For this you need to handle the rebalancing condition in your code and should process the ongoing message and commit it before rebalancing

    Like :

    private class HandleRebalance implements ConsumerRebalanceListener {
        public void onPartitionsAssigned(Collection partitions) {
            // Implement what you want to do once rebalancing is done.
        }
    
        public void onPartitionsRevoked(Collection partitions) {
            // commit current method
        }
    }
    

    and Use this syntax for subscribing the topic :

    kafkaConsumer.subscribe(topicNameList , new HandleRebalance())

    The advantage of doing this :

    1. Messages will not repeat when the rebalancing is taking place.

    2. No commit fail exception

提交回复
热议问题