Why is RabbitMQ not persisting messages on a durable queue?

旧时模样 提交于 2019-12-02 22:20:35

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'}
Daniel Roseman

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/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!