Tunker
Tunker

Reputation: 117

Make a Rabbit message persistent in PHP

I'm using http://www.php.net/manual/en/book.amqp.php to use Rabbit on my server. I have problem to make my messages persistent. I'm setting the exchange and the queue as AMQP_DURABLE, but after the server is restarted the queues are empty. It looks like the messages aren't saved to the disk.

I'm publishing my messages with: http://www.php.net/manual/en/amqpexchange.publish.php

Upvotes: 2

Views: 1615

Answers (1)

Daniel Figueroa
Daniel Figueroa

Reputation: 10696

You need to set the message as durable. What you're doing now is to only set the exchange and queue to durable, which is exactly what is happening.

So to save your messages to disk you need to set the delivery_mode to 2. Which means just that, durable.

Take a look at this thread to see it in action (code shamelessly copied from @Grzegorz Motyl's answer):

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

Upvotes: 1

Related Questions