CAMEL-13841: Allow manual Pulsar message acknowledgments #3094
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.
Addresses CAMEL-13841
Motivation
Pulsar messages are currently acknowledged immediately upon consumption. This could lead to lost messages if the application crashes or does not finish its unit of work. In such situations, it may be desirable to leave these messages unacknowledged so that they can be redelivered to another consumer.[Correction March 3, 2020 -- This is not correct. Pulsar messages are acknowledged after successful processing of the route, not immediately after consumption from the topic. Exceptions or errors on the route will correctly cause the message to remain unacknowledged.]Allow manual control of Pulsar message acknowledgement related routines. The end user can decide when to acknowledge, or negative acknowledge a Pulsar message within the route. This will become a necessity when support for asynchronous processing of Pulsar messages is added.
Modifications
Changed the
PulsarMessageListener
's received method to not acknowledge the message ifallowManualAcknowledgement
is true. Instead, we add an instance ofPulsarMessageReceipt
as a header on theExchange
so that the user can manually acknowledge the message at the appropriate time.Added
allowManualAcknowledgement
,ackTimeoutMillis
, andackGroupTimeMillis
as URI parameters. The latter two are Pulsar consumer configurations to allow for finer control over acknowledgements.Added
allowManualAcknowledgement
also as a component option so that it can default to true if absent in the Pulsar endpoint URI.Added the
pulsarMessageReceiptFactory
component option for providing an alternate implementation ofMessageReceipt
.Followed the same approach as camel-kafka:
CAMEL-11933
Verifying this change
Added the following test classes:
And added to:
PulsarComponentTest
Documentation
Added to
pulsar-component.adoc