4.7. Durable Queues and Durable Messages in Python

By default, the message queue will remain active in the broker as long as the broker is running, even though the program that created the queue has terminated. Should the broker crash, however, the queue and any messages would be lost. In order to avoid accidental loss as a result of machine failure, both queues and mesages can be made durable.
If a queue is durable, the queue survives a server crash, as well as any durable messages that have been placed on the queue. However, a queue may also be declared autoDelete, which means the queue is deleted automatically when the last client unsubscribes to the queue or terminates. If a queue is both durable and autoDelete, it is still deleted when the last client unsubscribes or terminates. To make a queue durable, specify durable="true" when you declare the queue:
session.queue_declare(queue="message_queue", durable="true")
To make a message durable, specify delivery_mode=session.delivery_mode.persistent in the message_transfer() function:
session.message_transfer(destination="amq.direct", content=request, delivery_mode=session.delivery_mode.persistent)