-
Notifications
You must be signed in to change notification settings - Fork 21
#210 ReactiveMessagePipline allowing negative ack #211
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
Conversation
lhotari
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution and putting effort in addressing the issue with negative acknowledgements, @vroyer.
Would it be possible to split this PR into the part that configures negativeAckRedeliveryBackoff and ackTimeoutRedeliveryBackoff? That could be handled separately before the other parts.
Another thought is that negative acknowledgement is already supported, but it's only when an error (Mono.error) is returned from the publisher that handles messages:
Lines 145 to 164 in 5317510
| private Mono<MessageResult<Void>> handleMessage(Message<T> message) { | |
| return Mono.from(this.messageHandler.apply(message)) | |
| .transform(this::decorateMessageHandler) | |
| .thenReturn(MessageResult.acknowledge(message.getMessageId())) | |
| .onErrorResume((throwable) -> { | |
| if (this.errorLogger != null) { | |
| try { | |
| this.errorLogger.accept(message, throwable); | |
| } | |
| catch (Exception ex) { | |
| LOG.error("Error in calling error logger", ex); | |
| } | |
| } | |
| else { | |
| LOG.error("Message handling for message id {} failed.", message.getMessageId(), throwable); | |
| } | |
| // TODO: nack doesn't work for batch messages due to Pulsar bugs | |
| return Mono.just(MessageResult.negativeAcknowledge(message.getMessageId())); | |
| }); | |
| } |
It looks like there are some gaps in the existing implementation's error handling. Just by looking at code , it seems that
Mono.from(this.messageHandler.apply(message)) should be wrapped with Mono.defer. Perhaps that's the reason why negative acknowledgement hasn't been working for your use case? Do you have a failing test case just for your use case? That type of test would also be a great addition to pulsar-client-reactive test cases.
Assuming that negative acknowledgements should work and are supported with the current interfaces, it would be better to focus on fixing that first before adding messageHandlerWithResult which shouldn't be needed.
|
Hi Lari, With the current implementation, the only way to nack for some business reason is to throw a RuntimeException and the retry is managed by reactor (see pipelineRetrySpec). In this case, the pulsar DeliveryBackoff is ineffective and this is the reason why I went further with the second commit. The pipeline retry should occurs when the handler unexpectedly fails, not when you need to nack a message for some business logic and rely on the pulsar redelivery to reprocess the message. To avoid a breaking change with the current auto-acknowledged messageHandler, the best solution seems to introduce another "messageHandler2" returning a MessageResult where you can ack or nack messages depending on your use case ? Regards, |
That's a bug in the current implementation.
Yes, that's a bug and it can be fixed without interface changes. The intention has been that when the Publisher signals an error, the message would be nacked. Do you see any problem in your use case with that? One of the bugs in the existing framework code for handling the message handler is the lack of using |
I just wonder why you don't have the same approche for both the consumer and the pipeline. The consumer returns a MessageResult to ack/nack, while the pipeline signal an error. In the last case, you need to carefully manage Publisher errors and PulsarClientException (due to connection issues) to not nack because of an ack issue.
I can't answer to this assumption. According to my tests with the proposed PR, the pipeline retry properly manages pulsar reconnection. |
The original purpose of the
We'll find out with test cases. |
|
Ok, you can just pick up the first commit for the DeliveryBackoff and fix the pipeline to nack without making a retry unless there is a PulsarClientException. That will be also fine. |
@vroyer There's a fix for the negative acknowledgement bug in #213. I'll close this PR. Please reopen a separate PR for the RedeliveryBackoff changes. |
Here is a proposal to provide a ReactiveMessagePipeline implementation allowing to negatively ack messages and provide a RedliveryBackoff to the ReactiveMessageSender. Thus, you can really benefit from Pulsar redelivery support.