Go – RabbitMQ: How to requeue message with counter


Is there any way to count how many time a job is requeued (via Reject or Nak) without manually requeu the job?
I need to retry a job for 'n' time and then drop it after 'n' time.

ps : Currently I requeue a job manually (drop old job, create a new job with the exact content and an extra Counter header if the Counter is not there or the value is less than 'n')

Best Solution

There are redelivered message property that set to true when message redelivered one or more time.

If you want to track redelivery count or left redelivers number (aka hop limit or ttl in IP stack) you have to store that value in message body or headers (literally - consume message, modify it and then publish it modified back to broker).

There are also similar question with answer which may help you: How do I set a number of retry attempts in RabbitMQ?