I'm setting up a RabbitMQ (v3.8.0) cluster with High Availability.
To enable messages persistency, I set exchanges and queues durable parameter to True.
{
"exchanges": [
{
"name": "my_direct_exchange",
"vhost": "my_vhost",
"type": "direct",
"durable": true,
"auto_delete": false,
"internal": false,
"arguments": {}
}
],
"queues": [
{
"name": "my_queue_direct",
"vhost": "my_vhost",
"durable": true,
"auto_delete": false,
"arguments": {}
}
]
}
Then, it seems there are 2 choices :
Either sending messages with delivery_mode=2
Or, setting lazy mode in queues (via policy configuration)
"policies": [
{
"vhost": "my_vhost",
"name": "my_policy",
"pattern": "",
"apply-to": "all",
"definition": {
"ha-mode": "all",
"ha-sync-mode": "automatic",
"queue-mode": "lazy"
}
}
]
Both of these choices will stores messages on disk. What is the difference between them ?
To enable messages persistency, I set exchanges and queues durable parameter to True.
To clarify, the durable
parameter for exchanges and queues does not affect individual message persistence. The durable
parameter ensures that those exchanges and queues survive broker restarts. True, if you have a non-durable queue with persistent messages, and restart the broker, that queue and those messages will be lost, so the durable
parameter is important.
You should use the persistent
flag, even with lazy queues. Why? Because you should also be using Publisher Confirms, and a message will only be confirmed when written to disk when persistent
is set.