When you execute basic.nack in RabbitMQ, what you are telling the server is that the message cannot be processed. If you have a dead letter / queue exchange configured, the message will be routed there if you set requeue=false . You cannot modify the contents of a message published in DLX, as they are only a reflection of the original published message.
This thread indicates that they are working on how the server automatically reports the number of delivery attempts, but this does not happen in the current version of RabbitMQ.
So ... at present, if it is important for you to know how many times your code has tried to process the message, you will need to:
- Reject the message by setting
requeue=false and - Publish the message again using the original exchange and routing key, but adding any information needed for the header. From a server perspective, this is a completely new message, and it will be placed at the back of the queue.
Please note that messages can still be requested if your consumer disconnects before sending any confirmation, positive or negative, back to the server. In this case, the original message will be delivered as is (without a custom header), and the redelivered flag will be set.
source share