Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens to fetched messages when RabbitMQ consumer crashes?

If I have a RabbitMQ consumer that retrieves 100 messages in bulk, but then it crashes before it can mark those messages as processed, are those messages lost? I want every message in the queue to be processed at least once. What's the recommended approach to deal with consumers that crash before they've acknowledged messages?

Does RabbitMQ put them back on the queue somehow, or what do I need to do to make it happen?

like image 846
user779159 Avatar asked Feb 21 '17 18:02

user779159


People also ask

When RabbitMQ quits or crashes What's the default behavior for queues and messages?

When RabbitMQ quits or crashes it will forget the queues and messages unless you tell it not to. Two things are required to make sure that messages aren't lost: we need to mark both the queue and messages as durable.

Can RabbitMQ lost messages?

Without acknowledgements, message loss is possible during publish and consume operations and only at most once delivery is guaranteed.

Can two consumers consume the same message RabbitMQ?

RabbitMQ has a plugin for consistent hash exchange. Using that exchange, and one consumer per queue, we can achieve message order with multiple consumers. The hash exchange distributes routing keys among queues, instead of messages among queues. This means all messages with the same routing key will go the same queue.

How long do messages stay in RabbitMQ?

In standard queues, messages are retained for at least 72 hours and will be deleted 72 hours later.


1 Answers

What's the recommended approach to deal with consumers that crash before they've acknowledged messages?

Let the rabbitmq do everything for you - messages that are not acknowledged are re-queued and will be delivered again to another (or even same) consumer.

Does RabbitMQ put them back on the queue somehow, or what do I need to do to make it happen?

See answer to first question. Simply don't acknowledge the messages before they're processed. This means also making sure that auto_ack flag is not set!

If I have a RabbitMQ consumer that retrieves 100 messages in bulk, but then it crashes before it can mark those messages as processed, are those messages lost?

See answer above - they are lost if they're automatically acknowledged.
Just a bit of reference, quoting from second tutorial:

If a consumer dies (its channel is closed, connection is closed, or TCP connection is lost) without sending an ack, RabbitMQ will understand that a message wasn't processed fully and will re-queue it. If there are other consumers online at the same time, it will then quickly redeliver it to another consumer. That way you can be sure that no message is lost, even if the workers occasionally die .

like image 114
cantSleepNow Avatar answered Sep 19 '22 18:09

cantSleepNow