Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added pause and resume to Java client Consumer #2961

Merged
merged 6 commits into from
Nov 10, 2018

Conversation

davidtinker
Copy link
Contributor

@davidtinker davidtinker commented Nov 8, 2018

Motivation

It is useful to be able to control message flow from the client but still use MessageListener to be notified when new messages arrive. Currently you have to use Consumer.receive() and receiverQueueSize which requires polling, which is inefficient for thousands of consumers. The C++ client has Consumer.pauseMessageListener() and resumeMessageListener().

Modifications

Added Consumer.pause() and Consumer.resume(). When paused the consumer does not send requests for more messages to the broker. This works when using MessageListener and Consumer.receive() which is why I didn't use the same names as the C++ client.

Result

Applications using the Java API can now do client side message flow control very easily based on their own internal state.

Copy link
Contributor

@merlimat merlimat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks good. Just left one comment regarding pause and receive interactions.

Can you also add unit tests for this feature, for both partitioned vs non-partitioned topics. Take a look at https://github.com/apache/pulsar/blob/master/pulsar-broker/src/test/java/org/apache/pulsar/client/api/SimpleProducerConsumerTest.java#L197 or https://github.com/apache/pulsar/blob/master/pulsar-broker/src/test/java/org/apache/pulsar/client/api/PartitionedProducerConsumerTest.java#L167

@merlimat merlimat added this to the 2.3.0 milestone Nov 8, 2018
@merlimat merlimat added the type/feature The PR added a new feature or issue requested a new feature label Nov 8, 2018
merlimat and others added 4 commits November 9, 2018 07:11
Co-Authored-By: davidtinker <david.tinker@gmail.com>
Co-Authored-By: davidtinker <david.tinker@gmail.com>
@davidtinker
Copy link
Contributor Author

I added tests. Tx.

Copy link
Contributor

@merlimat merlimat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@merlimat
Copy link
Contributor

merlimat commented Nov 9, 2018

run integration tests

@merlimat
Copy link
Contributor

run integration tests

@merlimat merlimat merged commit c1c699f into apache:master Nov 10, 2018
@davidtinker davidtinker deleted the consumer_pause branch November 10, 2018 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/feature The PR added a new feature or issue requested a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants