[improve][client] Enhance dynamic topic subscription management in PatternMultiTopicsConsumer #23794
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Main Issue: #xyz
Motivation
When subscribing to topics using regex patterns, it’s possible to encounter scenarios where some topics process messages slower than others. This can lead to significant performance bottlenecks, as slower topics might block others. There’s a need to manage such situations dynamically to ensure efficient processing and fair resource allocation among topics.
Related discussions can be found in this Reddit thread, which highlights issues similar to what we aim to address.
When using
MultiTopicsConsumerImpl
, we can call this.pulsar/pulsar-client/src/main/java/org/apache/pulsar/client/impl/MultiTopicsConsumerImpl.java
Lines 1246 to 1258 in 5a3a1f1
There is a test case that explains how to unsubscribe from a single topic.
pulsar/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/TopicsConsumerImplTest.java
Lines 660 to 663 in 5a3a1f1
This proposal seeks to integrate similar functionality into PatternMultiTopicsConsumerImpl, allowing dynamically remove or add specified topics.
Modifications
BlockTopics: Unsubscribe from topics by invoking onTopicsRemoved from TopicsChangedListener.
UnBlockTopics: Resubscribe to topics by invoking onTopicsAdded from the same listener.
These changes will enable dynamic topic management, greatly improving the consumer’s ability to adapt to changing topic loads and enhancing overall system resilience against individual slow topics.
Verifying this change
(Please pick either of the following options)
This change is a trivial rework / code cleanup without any test coverage.
(or)
This change is already covered by existing tests, such as (please describe tests).
(or)
This change added tests and can be verified as follows:
(example:)
Documentation
doc
doc-required
doc-not-needed
doc-complete
Matching PR in forked repository
PR in forked repository: