org.apache.kafka.clients.consumer
Interface ConsumerRebalanceCallback


public interface ConsumerRebalanceCallback

A callback interface that the user can implement to manage customized offsets on the start and end of every rebalance operation. This callback will execute in the user thread as part of the poll(long) API on every rebalance attempt. Default implementation of the callback will seek(offsets) to the last committed offsets in the onPartitionsAssigned() callback. And will commit offsets synchronously for the specified list of partitions to Kafka in the onPartitionsRevoked() callback.


Method Summary
 void onPartitionsAssigned(Consumer consumer, java.util.Collection<TopicPartition> partitions)
          A callback method the user can implement to provide handling of customized offsets on completion of a successful rebalance operation.
 void onPartitionsRevoked(Consumer consumer, java.util.Collection<TopicPartition> partitions)
          A callback method the user can implement to provide handling of offset commits to a customized store on the start of a rebalance operation.
 

Method Detail

onPartitionsAssigned

void onPartitionsAssigned(Consumer consumer,
                          java.util.Collection<TopicPartition> partitions)
A callback method the user can implement to provide handling of customized offsets on completion of a successful rebalance operation. This method will be called after a rebalance operation completes and before the consumer starts fetching data.

For examples on usage of this API, see Usage Examples section of KafkaConsumer

Parameters:
partitions - The list of partitions that are assigned to the consumer after rebalance

onPartitionsRevoked

void onPartitionsRevoked(Consumer consumer,
                         java.util.Collection<TopicPartition> partitions)
A callback method the user can implement to provide handling of offset commits to a customized store on the start of a rebalance operation. This method will be called before a rebalance operation starts and after the consumer stops fetching data. It is recommended that offsets should be committed in this callback to either Kafka or a custom offset store to prevent duplicate data

For examples on usage of this API, see Usage Examples section of KafkaConsumer

Parameters:
partitions - The list of partitions that were assigned to the consumer on the last rebalance