This is an automated email from the ASF dual-hosted git repository.
showuon pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git
The following commit(s) were added to refs/heads/trunk by this push:
new 111df859f0d MINOR: Add comment to onPartitionsLost override (#14121)
111df859f0d is described below
commit 111df859f0db7542eaa32a570bba5d83d5ef4a0b
Author: Federico Valeri <[email protected]>
AuthorDate: Fri Aug 11 04:34:55 2023 +0200
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 <[email protected]>, David Jacot <[email protected]>
---
examples/src/main/java/kafka/examples/Consumer.java | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/examples/src/main/java/kafka/examples/Consumer.java
b/examples/src/main/java/kafka/examples/Consumer.java
index abb69134e72..bd652e0a32e 100644
--- a/examples/src/main/java/kafka/examples/Consumer.java
+++ b/examples/src/main/java/kafka/examples/Consumer.java
@@ -151,15 +151,20 @@ public class Consumer extends Thread implements
ConsumerRebalanceListener {
@Override
public void onPartitionsRevoked(Collection<TopicPartition> partitions) {
Utils.printOut("Revoked partitions: %s", partitions);
+ // this can be used to commit pending offsets when using manual commit
and EOS is disabled
}
@Override
public void onPartitionsAssigned(Collection<TopicPartition> partitions) {
Utils.printOut("Assigned partitions: %s", partitions);
+ // this can be used to read the offsets from an external store or some
other initialization
}
@Override
public void onPartitionsLost(Collection<TopicPartition> 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
}
}