[Fixed]-Why is RabbitMQ not persisting messages on a durable queue?

6👍

To find out the messages delivery_mode you can consume it and look at the message properties:

>>> from tasks import add
>>> add.delay(2, 2)

>>> from celery import current_app
>>> conn = current_app.broker_connection()
>>> consumer = current_app.amqp.get_task_consumer(conn)

>>> messages = []
>>> def callback(body, message):
...     messages.append(message)
>>> consumer.register_callback(callback)
>>> consumer.consume()

>>> conn.drain_events(timeout=1)

>>> messages[0].properties
>>> messages[0].properties
{'application_headers': {}, 'delivery_mode': 2, 'content_encoding': u'binary',    'content_type': u'application/x-python-serialize'}
👤asksol

23👍

Making a queue durable is not the same as making the messages on it persistent. Durable queues mean they come up again automatically when the server has restarted – which has obviously happened in your case. But this doesn’t affect the messages themselves.

To make messages persistent, you have to also mark the message’s delivery_mode property to 2. See the classic write-up Rabbits and Warrens for a full explanation.

Edit: Full link is broken, but as of Dec 2013 you could still find the blog post from the main URL: http://blogs.digitar.com/jjww/

Leave a comment