adikou commented on code in PR #22270:
URL: https://github.com/apache/kafka/pull/22270#discussion_r3381432775
##########
clients/src/main/java/org/apache/kafka/clients/consumer/ConsumerRebalanceListener.java:
##########
@@ -89,33 +107,44 @@
* Here is pseudo-code for a callback implementation for saving offsets:
* <pre>
* {@code
- * public class SaveOffsetsOnRebalance implements ConsumerRebalanceListener {
- * private Consumer<?,?> consumer;
- *
- * public SaveOffsetsOnRebalance(Consumer<?,?> consumer) {
- * this.consumer = consumer;
- * }
- *
- * public void onPartitionsRevoked(Collection<TopicPartition>
partitions) {
+ * consumer.setConsumerRebalanceListener(new ConsumerRebalanceListener() {
+ * @Override
+ * public void onPartitionsRevoked(Collection<TopicPartition>
partitions, RebalanceConsumer rebalanceConsumer) {
* // save the offsets in an external store using some custom code
not described here
* for(TopicPartition partition: partitions)
- * saveOffsetInExternalStore(consumer.position(partition));
+ *
saveOffsetInExternalStore(rebalanceConsumer.position(partition));
* }
*
- * public void onPartitionsLost(Collection<TopicPartition> partitions) {
+ * @Override
+ * public void onPartitionsLost(Collection<TopicPartition> partitions,
RebalanceConsumer rebalanceConsumer) {
* // do not need to save the offsets since these partitions are
probably owned by other consumers already
* }
*
- * public void onPartitionsAssigned(Collection<TopicPartition>
partitions) {
+ * @Override
+ * public void onPartitionsAssigned(Collection<TopicPartition>
partitions, RebalanceConsumer rebalanceConsumer) {
* // read the offsets from an external store using some custom code
not described here
* for(TopicPartition partition: partitions)
- * consumer.seek(partition,
readOffsetFromExternalStore(partition));
+ * rebalanceConsumer.seek(partition,
readOffsetFromExternalStore(partition));
* }
- * }
+ * });
+ * consumer.subscribe(List.of("topic-1", "topic-2"));
* }
* </pre>
+ *
+ * TODO(adikou): re-enable as a real {@code @deprecated} javadoc tag once
internal call sites have
+ * migrated off ConsumerRebalanceListener; left for now to avoid
-Werror.
+ * @deprecated Since 4.4, replaced by {@link RebalanceListener}. New code
should implement
+ * {@link RebalanceListener} directly and register it via
+ * {@code Consumer.setRebalanceListener(RebalanceListener)}. This
interface remains for
+ * source compatibility with pre-existing one-argument callback
implementations and will
+ * continue to be supported for the foreseeable future to give
users time to migrate.
+ *
+ * @see RebalanceListener
+ * @see RebalanceConsumer
*/
-public interface ConsumerRebalanceListener {
+// TODO(adikou): re-enable @Deprecated once internal call sites have migrated;
left commented for now to avoid -Werror.
Review Comment:
Thanks. Updated javadoc in the suggested places.
I agree that the new hierarchy works rather nicely.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]