I've seen blog posts, as well as answer #2 from this SO question How do I set a number of retry attempts in RabbitMQ? recommending that one way to keep track of the retry count on a RabbitMQ message is to publish it again with an x-redelivered-count
header.
Is this done by setting the header on a message as it's headed to the dead-letter exchange, or is it done by making a fresh copy of the message with the same headers and body as before, but plus an incremented x-redelivered-count
(while ACKing the old copy of the message?), and if it can be done with the former, how would I edit the headers or body of a message before it is dead-lettered?
When you do a basic.nack
in RabbitMQ, what you are telling the server is that the message cannot be processed. If you have a dead letter exchange/queue configured, the message will be routed there if you set requeue=false
. You cannot alter the contents of a message published to the DLX, as they are only a reflection of the original message that was published.
This thread indicates that they are working on a way for the server to automatically report the number of delivery attempts, but it does not happen in the current version of RabbitMQ.
So... presently, if it is important for you to know the number of times that your code attempted to process the message, it will be necessary to:
requeue=false
andNote that messages still may be requeued in the case that your consumer disconnects before sending any acknowledgement, positve or negative, back to the server. In this case, the original message will be delivered as-is (no custom header) and the redelivered
flag will be set.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With