Browse Source

MINOR: Add comment to onPartitionsLost override (#14121)

This adds comments to the ConsumerRebalanceListener overrides, in order to briefly explain why we are overriding these methods, when they are called, and what you can or can't do. Especially onPartitionsLost can create some confusion given the default implementation.

Reviewers: Luke Chen <showuon@gmail.com>, David Jacot <djacot@confluent.io>
pull/13361/merge
Federico Valeri 1 year ago committed by GitHub
parent
commit
111df859f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      examples/src/main/java/kafka/examples/Consumer.java

5
examples/src/main/java/kafka/examples/Consumer.java

@ -151,15 +151,20 @@ public class Consumer extends Thread implements ConsumerRebalanceListener {
@Override @Override
public void onPartitionsRevoked(Collection<TopicPartition> partitions) { public void onPartitionsRevoked(Collection<TopicPartition> partitions) {
Utils.printOut("Revoked partitions: %s", partitions); Utils.printOut("Revoked partitions: %s", partitions);
// this can be used to commit pending offsets when using manual commit and EOS is disabled
} }
@Override @Override
public void onPartitionsAssigned(Collection<TopicPartition> partitions) { public void onPartitionsAssigned(Collection<TopicPartition> partitions) {
Utils.printOut("Assigned partitions: %s", partitions); Utils.printOut("Assigned partitions: %s", partitions);
// this can be used to read the offsets from an external store or some other initialization
} }
@Override @Override
public void onPartitionsLost(Collection<TopicPartition> partitions) { public void onPartitionsLost(Collection<TopicPartition> partitions) {
Utils.printOut("Lost partitions: %s", partitions); Utils.printOut("Lost partitions: %s", partitions);
// this is called when partitions are reassigned before we had a chance to revoke them gracefully
// we can't commit pending offsets because these partitions are probably owned by other consumers already
// nevertheless, we may need to do some other cleanup
} }
} }

Loading…
Cancel
Save