GeezerVison is showing github.com — KAFKA-20684 [9/N]: Deprecate ConsumerRebalanceListener for removal (#… · coderbruis/kafka@a3ee9be
File treeExpand file treeCollapse file tree Open diff view settings main/java/org/apache/kafka/clients/consumer test/java/org/apache/kafka/clients/consumer
streams/src/main/java/org/apache/kafka/streams/internals
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: clients/src/main/java/org/apache/kafka/clients/consumer/Consumer.java +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -56,8 +56,12 @@ public interface Consumer<K, V> extends Closeable { | 56 | 56 | void subscribe(Collection<String> topics); | 57 | 57 |
| 58 | 58 | /** | | 59 | + * @deprecated Since 4.5, to be removed in Kafka 5.0. Use {@link #setRebalanceListener(RebalanceListener)} | | 60 | + * followed by {@link #subscribe(Collection)} instead. | 59 | 61 | * @see KafkaConsumer#subscribe(Collection, ConsumerRebalanceListener) | 60 | 62 | */ | | 63 | + @Deprecated(since = "4.5", forRemoval = true) | | 64 | + @SuppressWarnings("removal") | 61 | 65 | void subscribe(Collection<String> topics, ConsumerRebalanceListener callback); | 62 | 66 |
| 63 | 67 | /** | @@ -66,8 +70,12 @@ public interface Consumer<K, V> extends Closeable { | 66 | 70 | void assign(Collection<TopicPartition> partitions); | 67 | 71 |
| 68 | 72 | /** | | 73 | + * @deprecated Since 4.5, to be removed in Kafka 5.0. Use {@link #setRebalanceListener(RebalanceListener)} | | 74 | + * followed by {@link #subscribe(Pattern)} instead. | 69 | 75 | * @see KafkaConsumer#subscribe(Pattern, ConsumerRebalanceListener) | 70 | 76 | */ | | 77 | + @Deprecated(since = "4.5", forRemoval = true) | | 78 | + @SuppressWarnings("removal") | 71 | 79 | void subscribe(Pattern pattern, ConsumerRebalanceListener callback); | 72 | 80 |
| 73 | 81 | /** | @@ -76,8 +84,12 @@ public interface Consumer<K, V> extends Closeable { | 76 | 84 | void subscribe(Pattern pattern); | 77 | 85 |
| 78 | 86 | /** | | 87 | + * @deprecated Since 4.5, to be removed in Kafka 5.0. Use {@link #setRebalanceListener(RebalanceListener)} | | 88 | + * followed by {@link #subscribe(SubscriptionPattern)} instead. | 79 | 89 | * @see KafkaConsumer#subscribe(SubscriptionPattern, ConsumerRebalanceListener) | 80 | 90 | */ | | 91 | + @Deprecated(since = "4.5", forRemoval = true) | | 92 | + @SuppressWarnings("removal") | 81 | 93 | void subscribe(SubscriptionPattern pattern, ConsumerRebalanceListener callback); | 82 | 94 |
| 83 | 95 | /** | |
Collapse file Copy file name to clipboardExpand all lines: clients/src/main/java/org/apache/kafka/clients/consumer/ConsumerRebalanceListener.java +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 116 | 116 | * Here is pseudo-code for a callback implementation for saving offsets: | 117 | 117 | * <pre> | 118 | 118 | * {@code | 119 | | - * consumer.setRebalanceListener(new ConsumerRebalanceListener() { | | 119 | + * consumer.setRebalanceListener(new RebalanceListener() { | 120 | 120 | * @Override | 121 | 121 | * public void onPartitionsRevoked(Collection<TopicPartition> partitions, RebalanceConsumer rebalanceConsumer) { | 122 | 122 | * // save the offsets in an external store using some custom code not described here | | 140 | 140 | * } | 141 | 141 | * </pre> | 142 | 142 | * | | 143 | + * @deprecated Since 4.5, to be removed in Kafka 5.0. Use {@link RebalanceListener} and register it via | | 144 | + * {@link Consumer#setRebalanceListener(RebalanceListener)} instead. | 143 | 145 | * @see RebalanceListener | 144 | 146 | * @see RebalanceConsumer | 145 | 147 | */ | | 148 | +@Deprecated(since = "4.5", forRemoval = true) | 146 | 149 | @InterfaceAudience.Public | 147 | 150 | public interface ConsumerRebalanceListener extends RebalanceListener { | 148 | 151 |
| |
Collapse file Copy file name to clipboardExpand all lines: clients/src/main/java/org/apache/kafka/clients/consumer/KafkaConsumer.java +12-6Lines changed: 12 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -712,18 +712,19 @@ public Set<String> subscription() { | 712 | 712 | * It is guaranteed, however, that the partitions revoked/assigned through this interface are from topics | 713 | 713 | * subscribed in this call. See {@link ConsumerRebalanceListener} for more details. | 714 | 714 | * | 715 | | - * <p>deprecated Use {@link #subscribe(Collection)} to subscribe and | 716 | | - * {@link Consumer#setRebalanceListener(RebalanceListener)} to register a rebalance listener | 717 | | - * separately. | 718 | 715 | * @param topics The list of topics to subscribe to | 719 | 716 | * @param listener Non-null listener instance to get notifications on partition assignment/revocation for the | 720 | 717 | * subscribed topics | 721 | 718 | * @throws IllegalArgumentException If topics is null or contains null or empty elements, or if listener is null | 722 | 719 | * @throws IllegalStateException If {@code subscribe()} is called previously with pattern, or assign is called | 723 | 720 | * previously (without a subsequent call to {@link #unsubscribe()}), or if not | 724 | 721 | * configured at-least one partition assignment strategy | | 722 | + * @deprecated Since 4.5, to be removed in Kafka 5.0. Use {@link #subscribe(Collection)} with | | 723 | + * {@link Consumer#setRebalanceListener(RebalanceListener)}. | 725 | 724 | */ | | 725 | + @Deprecated(since = "4.5", forRemoval = true) | 726 | 726 | @Override | | 727 | + @SuppressWarnings("removal") | 727 | 728 | public void subscribe(Collection<String> topics, ConsumerRebalanceListener listener) { | 728 | 729 | delegate.subscribe(topics, listener); | 729 | 730 | } | @@ -778,8 +779,12 @@ public void subscribe(Collection<String> topics) { | 778 | 779 | * @throws IllegalStateException If {@code subscribe()} is called previously with topics, or assign is called | 779 | 780 | * previously (without a subsequent call to {@link #unsubscribe()}), or if not | 780 | 781 | * configured at-least one partition assignment strategy | | 782 | + * @deprecated Since 4.5, to be removed in Kafka 5.0. Use {@link #subscribe(Pattern)} with | | 783 | + * {@link Consumer#setRebalanceListener(RebalanceListener)}. | 781 | 784 | */ | | 785 | + @Deprecated(since = "4.5", forRemoval = true) | 782 | 786 | @Override | | 787 | + @SuppressWarnings("removal") | 783 | 788 | public void subscribe(Pattern pattern, ConsumerRebalanceListener listener) { | 784 | 789 | delegate.subscribe(pattern, listener); | 785 | 790 | } | @@ -824,17 +829,18 @@ public void subscribe(Pattern pattern) { | 824 | 829 | * when there is a change to the topics matching the provided pattern and when consumer group membership changes. | 825 | 830 | * Group rebalances only take place during an active call to {@link #poll(Duration)}. | 826 | 831 | * | 827 | | - * <p>deprecated Use {@link #subscribe(SubscriptionPattern)} to subscribe and | 828 | | - * {@link Consumer#setRebalanceListener(RebalanceListener)} to register a rebalance listener | 829 | | - * separately. | 830 | 832 | * @param pattern Pattern to subscribe to, that must be compatible with Google RE2/J. | 831 | 833 | * @param listener Non-null listener instance to get notifications on partition assignment/revocation for the | 832 | 834 | * subscribed topics. | 833 | 835 | * @throws IllegalArgumentException If pattern is null or empty, or if the listener is null. | 834 | 836 | * @throws IllegalStateException If {@code subscribe()} is called previously with topics, or assign is called | 835 | 837 | * previously (without a subsequent call to {@link #unsubscribe()}). | | 838 | + * @deprecated Since 4.5, to be removed in Kafka 5.0. Use {@link #subscribe(SubscriptionPattern)} with | | 839 | + * {@link Consumer#setRebalanceListener(RebalanceListener)}. | 836 | 840 | */ | | 841 | + @Deprecated(since = "4.5", forRemoval = true) | 837 | 842 | @Override | | 843 | + @SuppressWarnings("removal") | 838 | 844 | public void subscribe(SubscriptionPattern pattern, ConsumerRebalanceListener listener) { | 839 | 845 | delegate.subscribe(pattern, listener); | 840 | 846 | } | |
Collapse file Copy file name to clipboardExpand all lines: clients/src/main/java/org/apache/kafka/clients/consumer/MockConsumer.java +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -188,7 +188,9 @@ public synchronized void subscribe(Collection<String> topics) { | 188 | 188 | subscribeInternal(topics, null); | 189 | 189 | } | 190 | 190 |
| | 191 | + @Deprecated(since = "4.5", forRemoval = true) | 191 | 192 | @Override | | 193 | + @SuppressWarnings("removal") | 192 | 194 | public synchronized void subscribe(Pattern pattern, final ConsumerRebalanceListener listener) { | 193 | 195 | if (listener == null) | 194 | 196 | throw new IllegalArgumentException("RebalanceListener cannot be null"); | @@ -201,7 +203,9 @@ public synchronized void subscribe(Pattern pattern) { | 201 | 203 | subscribeInternal(pattern, null); | 202 | 204 | } | 203 | 205 |
| | 206 | + @Deprecated(since = "4.5", forRemoval = true) | 204 | 207 | @Override | | 208 | + @SuppressWarnings("removal") | 205 | 209 | public synchronized void subscribe(SubscriptionPattern pattern, ConsumerRebalanceListener listener) { | 206 | 210 | if (listener == null) | 207 | 211 | throw new IllegalArgumentException("RebalanceListener cannot be null"); | @@ -214,7 +218,9 @@ public synchronized void subscribe(SubscriptionPattern pattern) { | 214 | 218 | subscribeInternal(pattern, null); | 215 | 219 | } | 216 | 220 |
| | 221 | + @Deprecated(since = "4.5", forRemoval = true) | 217 | 222 | @Override | | 223 | + @SuppressWarnings("removal") | 218 | 224 | public void subscribe(Collection<String> topics, final ConsumerRebalanceListener listener) { | 219 | 225 | if (listener == null) | 220 | 226 | throw new IllegalArgumentException("RebalanceListener cannot be null"); | |
Collapse file Copy file name to clipboardExpand all lines: clients/src/main/java/org/apache/kafka/clients/consumer/internals/AsyncKafkaConsumer.java +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2152,6 +2152,7 @@ public void subscribe(Collection<String> topics) { | 2152 | 2152 | } | 2153 | 2153 |
| 2154 | 2154 | @Override | | 2155 | + @SuppressWarnings("removal") | 2155 | 2156 | public void subscribe(Collection<String> topics, ConsumerRebalanceListener listener) { | 2156 | 2157 | if (listener == null) | 2157 | 2158 | throw new IllegalArgumentException("RebalanceListener cannot be null"); | @@ -2174,6 +2175,7 @@ public void subscribe(Pattern pattern) { | 2174 | 2175 | } | 2175 | 2176 |
| 2176 | 2177 | @Override | | 2178 | + @SuppressWarnings("removal") | 2177 | 2179 | public void subscribe(SubscriptionPattern pattern, ConsumerRebalanceListener listener) { | 2178 | 2180 | if (listener == null) | 2179 | 2181 | throw new IllegalArgumentException("RebalanceListener cannot be null"); | @@ -2186,6 +2188,7 @@ public void subscribe(SubscriptionPattern pattern) { | 2186 | 2188 | } | 2187 | 2189 |
| 2188 | 2190 | @Override | | 2191 | + @SuppressWarnings("removal") | 2189 | 2192 | public void subscribe(Pattern pattern, ConsumerRebalanceListener listener) { | 2190 | 2193 | if (listener == null) | 2191 | 2194 | throw new IllegalArgumentException("RebalanceListener cannot be null"); | |
Collapse file Copy file name to clipboardExpand all lines: clients/src/main/java/org/apache/kafka/clients/consumer/internals/ClassicKafkaConsumer.java +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -460,6 +460,7 @@ public void unregisterMetricFromSubscription(KafkaMetric metric) { | 460 | 460 | } | 461 | 461 |
| 462 | 462 | @Override | | 463 | + @SuppressWarnings("removal") | 463 | 464 | public void subscribe(Collection<String> topics, ConsumerRebalanceListener listener) { | 464 | 465 | if (listener == null) | 465 | 466 | throw new IllegalArgumentException("RebalanceListener cannot be null"); | @@ -532,6 +533,7 @@ private void subscribeInternal(Collection<String> topics, RebalanceListener list | 532 | 533 | } | 533 | 534 |
| 534 | 535 | @Override | | 536 | + @SuppressWarnings("removal") | 535 | 537 | public void subscribe(Pattern pattern, ConsumerRebalanceListener listener) { | 536 | 538 | if (listener == null) | 537 | 539 | throw new IllegalArgumentException("RebalanceListener cannot be null"); | @@ -545,6 +547,7 @@ public void subscribe(Pattern pattern) { | 545 | 547 | } | 546 | 548 |
| 547 | 549 | @Override | | 550 | + @SuppressWarnings("removal") | 548 | 551 | public void subscribe(SubscriptionPattern pattern, ConsumerRebalanceListener callback) { | 549 | 552 | throw new UnsupportedOperationException(String.format("Subscribe to RE2/J pattern is not supported when using" + | 550 | 553 | "the %s protocol defined in config %s", GroupProtocol.CLASSIC, ConsumerConfig.GROUP_PROTOCOL_CONFIG)); | |
Collapse file Copy file name to clipboardExpand all lines: clients/src/test/java/org/apache/kafka/clients/consumer/ConsumerRebalanceListenerTest.java +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 30 | 30 | import static org.junit.jupiter.api.Assertions.assertTrue; | 31 | 31 | import static org.mockito.Mockito.mock; | 32 | 32 |
| | 33 | +@SuppressWarnings("removal") // this suite exists to cover the deprecated bridge | 33 | 34 | public class ConsumerRebalanceListenerTest { | 34 | 35 |
| 35 | 36 | private static final TopicPartition TP0 = new TopicPartition("topic", 0); | |
Collapse file Copy file name to clipboardExpand all lines: clients/src/test/java/org/apache/kafka/clients/consumer/KafkaConsumerTest.java +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4229,6 +4229,7 @@ public void testPollSendsRequestToJoin(GroupProtocol groupProtocol) throws Inter | 4229 | 4229 |
| 4230 | 4230 | @ParameterizedTest | 4231 | 4231 | @EnumSource(value = GroupProtocol.class, names = "CLASSIC") | | 4232 | + @SuppressWarnings("removal") | 4232 | 4233 | public void testSubscribeToRe2jPatternNotSupportedForClassicConsumer(GroupProtocol groupProtocol) { | 4233 | 4234 | consumer = newConsumerNoAutoCommit(groupProtocol, time, mock(NetworkClient.class), subscription, | 4234 | 4235 | mock(ConsumerMetadata.class)); | |
Collapse file Copy file name to clipboardExpand all lines: clients/src/test/java/org/apache/kafka/clients/consumer/MockConsumerTest.java +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -142,6 +142,7 @@ public void testDurationBasedOffsetReset() { | 142 | 142 | } | 143 | 143 |
| 144 | 144 | @Test | | 145 | + @SuppressWarnings("removal") | 145 | 146 | public void testRebalanceListener() { | 146 | 147 | final List<TopicPartition> revoked = new ArrayList<>(); | 147 | 148 | final List<TopicPartition> assigned = new ArrayList<>(); | @@ -190,6 +191,7 @@ public void onPartitionsAssigned(Collection<TopicPartition> partitions) { | 190 | 191 | } | 191 | 192 |
| 192 | 193 | @Test | | 194 | + @SuppressWarnings("removal") | 193 | 195 | public void testRe2JPatternSubscription() { | 194 | 196 | assertThrows(IllegalArgumentException.class, () -> consumer.subscribe((SubscriptionPattern) null)); | 195 | 197 | assertThrows(IllegalArgumentException.class, () -> consumer.subscribe(new SubscriptionPattern(""))); | |
Collapse file Copy file name to clipboardExpand all lines: clients/src/test/java/org/apache/kafka/clients/consumer/internals/AsyncKafkaConsumerTest.java +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2418,6 +2418,7 @@ public void testSeekToEnd() { | 2418 | 2418 | } | 2419 | 2419 |
| 2420 | 2420 | @Test | | 2421 | + @SuppressWarnings("removal") | 2421 | 2422 | public void testSubscribeToRe2JPatternValidation() { | 2422 | 2423 | consumer = newConsumer(); | 2423 | 2424 |
| @@ -2434,6 +2435,7 @@ public void testSubscribeToRe2JPatternValidation() { | 2434 | 2435 | } | 2435 | 2436 |
| 2436 | 2437 | @Test | | 2438 | + @SuppressWarnings("removal") | 2437 | 2439 | public void testSubscribeToRe2JPatternThrowsIfNoGroupId() { | 2438 | 2440 | consumer = newConsumer(requiredConsumerConfig()); | 2439 | 2441 | assertThrows(InvalidGroupIdException.class, () -> consumer.subscribe(new SubscriptionPattern("t*"))); | @@ -2442,6 +2444,7 @@ public void testSubscribeToRe2JPatternThrowsIfNoGroupId() { | 2442 | 2444 | } | 2443 | 2445 |
| 2444 | 2446 | @Test | | 2447 | + @SuppressWarnings("removal") | 2445 | 2448 | public void testSubscribeToRe2JPatternGeneratesEvent() { | 2446 | 2449 | consumer = newConsumer(); | 2447 | 2450 | completeTopicRe2JPatternSubscriptionChangeEventSuccessfully(); | |
|