- Kafka Broker has 3 partitions.
- Kafka Consumer instance' count is 3.
- Suddenly, one Consumer instance died.
I know that if a Kafka Consumer instance dies, the Kafka Broker is rebalancing and another consumer instance gets allocated to that partition.
I wonder if it is correct to assume that another instance consumes all of the partition it originally consumes and then allocates and consumes dead partitions.
(And do I have to implement ConsumerRebalanceListener in client code?)
If this is the case, can there be any delay in consuming the message?
Thank you.
The default partition assignment strategy is RangeAssignor. For each subscribed topic, this strategy:
At the beginning of your example, there are
This strategy assigned:
Suppose consumer C dies. Rebalancing executes this strategy on
The strategy assigns:
So in this scenario, the set of partitions assigned to consumer B after rebalancing does not contain the partition assigned to it before rebalancing.
If I am not mistaken rebalancing will interrupt the processing of your different consumers.
If you are commiting your offset at the end of each batch, that means that all the data that had already been processed in your batch will be reprocessed again.
To avoid that you can either use
consumer.commitAsync()
that allows you to commit your offset in the middle of a batch processing, or implementConsumerRebalanceListener
as you infered.From Kafka the definitive Guide
And to answer your last question : Yes, rebalancing implies a delay in consuming messages.