81

I understand that 2 options are available:

  • "Non-persistent"
  • "Persistent"

But what does this actually mean?

"Non-persistent" as in : the AMQP fabric will try to deliver the message if there are no consumers, the message will be dropped?

"Persistent" as in : AMQP will retry the message until a consumer accepts it??

jldupont
  • 93,734
  • 56
  • 203
  • 318

3 Answers3

73

Messages marked as 'persistent' that are delivered to 'durable' queues will be logged to disk. Durable queues are recovered in the event of a crash, along with any persistent messages they stored prior to the crash.

fgblomqvist
  • 2,244
  • 2
  • 32
  • 44
alexis
  • 2,129
  • 15
  • 6
  • I do not understand why you can declare an Exchange durable. And on the other side you "could"!? declare a queue that "corresponds" to that Exchange nondurable? Or for example if you would declare a Exchange NONDURABLE but a queue durable, and there would be a crash. Could I recover that durable queue in the nondurable exchange? @alexis – noBillSide Jun 27 '13 at 13:52
  • 14
    "durability" only means the Exchange or Queue will survive a server restart.. This does not mean the messages being stored in a durable queue will survive... That would _also_ require a message level property `.deliveryMode = 2`. (I just tested these cases) – Myobis Jan 06 '14 at 09:04
23

delivery_mode in AMQP determines if message will be stored on disk after broker restarts. You can mark messages as persistent - by seting delivery_mode property = 2 when you publish message for instance in PHP (PECL AMQP extension):

$exchange->publish($text, $routingKey, null, array('delivery_mode' => 2));

You would also need to declare queue as durable (or it will be dropped after broker stops)

$queue->setFlags(AMQP_DURABLE);
j0k
  • 22,600
  • 28
  • 79
  • 90
Greg Motyl
  • 2,478
  • 17
  • 31
  • 1
    Will the continue to be stored on disk even after they are processed? Or is it only a guarantee that they will be persisted until they get processed? – cs_pupil Jan 19 '23 at 17:47
0

The value of the delivery mode will tell RabbitMQ if it’s allowed to keep the message in memory when the message is placed in a queue (non-persistent) or if it must store the message on disk first (persistent).

Chris Bao
  • 2,418
  • 8
  • 35
  • 62