Search code examples
client-serverrabbitmqmq

RabbitMQ: try send message again


I have server which send message into MQ. Message remove from queue when worker answer:

channel.basic_ack(delivery_tag=method_frame.delivery_tag)

but when worker generate error it doesn't answer about good delivered. Is it possible to route this message to other worker or send this message into end of queue and try again later. Is RabbitMQ has got mechanism which set time out for message. When timeout is over message try send to worker again or do I need to implement it yourself?


Solution

  • If your worker does not acknowledge the message it is not removed from the queue, however if the connection between the worker and rabbit-mq survives rabbit-mq has no way of knowing that the message isn't in workers the buffer.

    There are several ways to solving this, and it is mainly dependent on your application structure.

    The easiest is to set prefetch to one and make sure that you reset the connection between rabbitmq and your worker whenever there is a problem.

    You could also look into nacking your messages however I don't know if this will requeue them or not.

    You could ofcourse also do as you say and send the message that you got into another queue or something like that. However keep in mind that if you don't ACK your messages you'll end up having a larger queue than you really think because rabbit won't remove items from the queue unless they are acked (actually this is dependent on your configuration of the queue).