Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RabbitMQ: How to requeue message with counter

Tags:

go

rabbitmq

amqp

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')

like image 855
fzerorubigd Avatar asked Aug 10 '14 06:08

fzerorubigd


People also ask

How do you Requeue Unacked messages in RabbitMQ?

To reject messages in bulk, clients set the multiple flag of the basic. nack method to true . The broker will then reject all unacknowledged, delivered messages up to and including the message specified in the delivery_tag field of the basic. nack method.

What happens to unacknowledged messages in RabbitMQ?

RabbitMQ Unacked Messages are the messages that are not Acknowledged. If a consumer fails to acknowledge messages, the RabbitMQ will keep sending new messages until the prefetch value set for the associated channel is equal to the number of RabbitMQ Unacked Messages count.


1 Answers

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?

like image 127
pinepain Avatar answered Oct 11 '22 11:10

pinepain