Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will rabbitmq server recover messages for queue marked as durable, when rabbitmq-server gets crashed?

I am going through the documentation of AMQP given by Rabbitmq official site. It says that

Queue Durability Durable queues are persisted to disk and thus survive broker restarts. Queues that are not durable are called transient. Not all scenarios and use cases mandate queues to be durable.

Durability of a queue does not make messages that are routed to that queue durable. If broker is taken down and then brought back up, durable queue will be re-declared during broker startup, however, only persistent messages will be recovered.

However I am confused about following scenarios, when Message broker crashes :-

  1. Message is delivered to Message Exchange by producer, but not routed to queue marked as durable.
  2. Message is delivered to Message Exchange by producer, which in turn routes to queue marked as durable, but message is in the queue and not consumed by consumer.
  3. Message is delivered to Message Exchange by producer, which in turn routes to queue marked as durable, but message is in the queue and consumed by consumer, but no acknowledgement has been send by consumer to the queue.

In all the above cases, will the messages be available on next start of rabbit-mq server ?

Moreover, the documentation makes distinction between normal message and persistent messages, as only persistent messages will be recovered. What's the difference between both message types ?

Thanks in advance.

like image 703
Mangu Singh Rajpurohit Avatar asked Mar 06 '23 11:03

Mangu Singh Rajpurohit


1 Answers

A durable queue will persist after a broker restart. This mean that after a restart the queue will be recreated automatically without the need you create it again manually. This only ensures that the queue is going to continue existing but not any messages that it contains.

Now, persistent messages will be written to disk as soon as they reach the queue, this is independent of the queue (durable or not).

So answering your questions. If you want your messages to be recovered after a restart, declare them persistent always. Supposing that, your scenarios will be:

  1. Message will be lost because it hasn't reached the queue yet.
  2. Message will be recovered because it reached the queue.
  3. Message will be recovered and sent again with the redelivered flag on it when it is delivered again (whether to the same consumer or a different one). This is a hint that a consumer may have seen this message before.

Notice that persistent message has no effect inside a non-durable queue; When the server restarts, the queue will not be recreated and thus the messages will not be recreated from the persistency log file. This is also true for every non-durable queue that the message may be routed to: Once a message is routed to a non-durable queue it gets deleted from the persistency log file and is not considered persistent anymore.

like image 116
Jesferman Avatar answered Apr 27 '23 17:04

Jesferman