1
votes

I'm using kafka consumer api 0.10.2.1.

KafkaConsumer provides a callback for partition assignment and revoking:

consumer.subscribe(topics, consumerRebalanceListener);

Where consumerRebalanceListener has two methods:

public void onPartitionsRevoked(Collection<TopicPartition> partitions);
public void onPartitionsAssigned(Collection<TopicPartition> partitions);

As everything in Kafka consumer happens in single thread, and inside poll() method, these callbacks are called from inside poll() method. The question is, can they both be called from one poll() call or they always require two separate poll() calls?

1

1 Answers

4
votes

In my opinion, they are called from on poll() call. When a consumer instance starts to join the group, onPartitionsRevoked is firstly invoked to revoke all the partitions assigned to this instance and sends the JoinGroup request. Then it blocks indefinitely until the response is received. If it joins group successfully, it executes user's callback by calling onPartitionsAssigned. All of these are finished in one single round of poll.