phprabbitmqphp-amqp

RabbitMQ retrying mechanism


I'm using rabbitMQ, I take every message from queue with basic_get without automatically acking procedure, which means the message remain in queue until I ack or nack the message.

Sometimes I've messages that can't be processed because of some exception thrown, which prevented them from being fully processed.

In these cases, I want to try again lets say twice immediately and if I still couldn't process them as a result - I want to try again 3 more times in one hour interval, if then all fails then I would like to nack the message and remove it from queue permanently.

Question is if there any mechanism in rabbitMQ which provide me with message retries (which also counting the number of retries), and ability to choose when the retry will be launch- some kind of postpone mechanism?


Solution

  • You should use multiple queues for that.

    I had a similar issue, the way I handled that problem is by moving the messages who encountered a problem into another queue.

    If you have an exception thrown, then catch it, ack the message and move it into let's say error_queue_1. You can setup a 2nd listener (with a different timer), who will process the error_queue_1.

    And you can repeat that process as many times as you feel it is required.

    This will also allow you to have an idea of how many messages had problems, which one, etc.