0
0
RabbitMQdevops~10 mins

Message durability and persistence in RabbitMQ - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Message durability and persistence
Producer sends message
Is queue durable?
NoMessage lost if broker restarts
Yes
Is message persistent?
NoMessage lost if broker restarts
Yes
Message stored on disk
Broker restarts
Message recovered from disk
Consumer receives message
This flow shows how message durability and persistence protect messages from loss during broker restarts by storing them on disk.
Execution Sample
RabbitMQ
channel.queue_declare(queue='task_queue', durable=True)
channel.basic_publish(exchange='', routing_key='task_queue',
                      body='Hello World!',
                      properties=pika.BasicProperties(delivery_mode=2))
Declare a durable queue and publish a persistent message to it.
Process Table
StepActionQueue Durable?Message Persistent?Result
1Declare queue 'task_queue'TrueN/AQueue created as durable
2Publish message 'Hello World!'TrueTrueMessage stored on disk
3Broker restartsTrueTrueMessage recovered from disk
4Consumer receives messageTrueTrueMessage delivered to consumer
5EndN/AN/AMessage safely persisted and delivered
💡 Message is durable and persistent, so it survives broker restart and is delivered.
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4Final
queue_durableFalseTrueTrueTrueTrueTrue
message_persistentFalseN/ATrueTrueTrueTrue
message_stored_on_diskFalseFalseTrueTrueTrueTrue
message_deliveredFalseFalseFalseFalseTrueTrue
Key Moments - 3 Insights
Why does the message get lost if the queue is not durable?
Because as shown in step 1 and 2 of the execution_table, if the queue is not durable, messages are kept only in memory and lost on broker restart.
What happens if the message is not marked persistent?
Even if the queue is durable, a non-persistent message is not saved to disk (step 2), so it can be lost on broker restart.
Does marking the queue durable alone guarantee message safety?
No, both the queue must be durable and the message must be persistent to ensure messages survive broker restarts, as shown in steps 1 and 2.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step is the message stored on disk?
AStep 1
BStep 3
CStep 2
DStep 4
💡 Hint
Check the 'Result' column for when the message is stored on disk.
According to variable_tracker, what is the value of 'message_delivered' after Step 3?
ATrue
BFalse
CN/A
DUnknown
💡 Hint
Look at the 'message_delivered' row under 'After Step 3' column.
If the queue was not durable, what would happen at Step 3?
AMessage lost on broker restart
BMessage recovered from disk
CMessage delivered to consumer
DQueue recreated as durable
💡 Hint
Refer to the concept_flow where non-durable queues cause message loss on restart.
Concept Snapshot
Message durability means the queue survives broker restarts.
Message persistence means messages are saved to disk.
Both must be true to avoid message loss.
Declare queue with durable=True.
Publish messages with delivery_mode=2 (persistent).
This ensures messages survive broker crashes.
Full Transcript
This visual execution shows how message durability and persistence work in RabbitMQ. First, the producer declares a queue with durability set to true, meaning the queue will survive broker restarts. Then, the producer sends a message marked as persistent, which means the message will be saved to disk. When the broker restarts, it recovers the message from disk because both the queue and message are durable and persistent. Finally, the consumer receives the message safely. If either the queue is not durable or the message is not persistent, the message can be lost on broker restart. This trace helps beginners see the step-by-step state changes and understand why both settings are important for message safety.