Search code examples
javamessage-queueapache-pulsar

How should Apache Pulsar Consumer.acknowledgeAsync() failure be handled?


I am using Consumer.acknowledgeAsync() to ack messages in my Java service and was wondering what happens if the ack fails? Should I retry the operation a few times and discard my consumer when retries are exhausted?

I am counting the number of messages being processed for flow-control to limit memory usage.


Solution

  • Usually, If message was not ack-ed successfully, after ackTimeout, the message will be redelivered from broker to consumer again. So here, most of the case, it is no need to retry.

    maybe some handling like this is enough:

    consumer.acknowledgeAsync(msgId)
        .thenAccept(consumer -> successHandlerMethod())
        .exceptionally(exception -> failHandlerMethod());