0
0
RabbitMQdevops~10 mins

Mirrored queues for redundancy in RabbitMQ - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Mirrored queues for redundancy
Client sends message
Message arrives at Master Queue
Master replicates message
Messages copied to Mirror Queues
Consumers read from Master or Mirror
If Master fails -> Mirror promoted to Master
Message flow continues without loss
Messages sent to the master queue are copied to mirror queues on other nodes. If the master fails, a mirror takes over to keep messages safe.
Execution Sample
RabbitMQ
rabbitmqctl set_policy ha-all "" '{"ha-mode":"all"}'
rabbitmqctl list_queues name policy

# Publish message to queue 'task_queue'
# Consumer reads from queue
# Master failure triggers mirror takeover
This setup command creates mirrored queues across all nodes for redundancy.
Process Table
StepActionMaster Queue StateMirror Queues StateResult
1Create queue 'task_queue' with ha-mode=allEmptyEmpty on all mirrorsQueue created and mirrored
2Publish message 'msg1' to masterContains 'msg1'Contains 'msg1' replicatedMessage replicated to mirrors
3Consumer reads 'msg1' from masterEmptyContains 'msg1'Message acknowledged on master
4Master node failsUnavailableContains 'msg1' on mirrorsMirror promoted to master
5Consumer reads 'msg1' from new masterEmptyEmpty after ackMessage consumed without loss
6Publish message 'msg2' to new masterContains 'msg2'Contains 'msg2' on mirrorsNew messages replicated
7Consumer reads 'msg2' from new masterEmptyEmpty after ackMessage consumed
8Master restored and rejoins clusterEmptyEmptyCluster stable with mirrored queues
💡 Execution stops after cluster stabilizes with mirrored queues ensuring no message loss despite master failure.
Status Tracker
VariableStartAfter Step 2After Step 3After Step 4After Step 5After Step 6After Step 7Final
Master Queue MessagesEmpty['msg1']EmptyUnavailableEmpty['msg2']EmptyEmpty
Mirror Queues MessagesEmpty['msg1']['msg1']['msg1']Empty['msg2']EmptyEmpty
Master Node StatusActiveActiveActiveFailedFailedActiveActiveRestored
Mirror Node StatusActiveActiveActiveActive (promoted)Active (promoted)Active (promoted)Active (promoted)Active
Key Moments - 3 Insights
Why does the message still exist on mirror queues after the master queue message is acknowledged?
Because the master acknowledges the message first, but mirrors keep a copy until they also confirm consumption, ensuring no message loss if master fails (see step 3 and 5).
What happens to message flow when the master node fails?
The mirror queue is promoted to master and continues message delivery without interruption, as shown in step 4 and 5.
Why do we need to set the policy with ha-mode=all?
This policy tells RabbitMQ to mirror the queue on all nodes, ensuring redundancy and failover capability (step 1).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the state of the master queue after step 3?
AEmpty
BContains 'msg1'
CUnavailable
DContains 'msg2'
💡 Hint
Check the 'Master Queue State' column at step 3 in the execution table.
At which step does the mirror queue get promoted to master?
AStep 2
BStep 4
CStep 6
DStep 8
💡 Hint
Look for 'Mirror promoted to master' in the 'Result' column.
If the ha-mode policy was set to 'nodes' instead of 'all', how would the message replication change?
AMessages replicate to all nodes
BNo replication happens
CMessages replicate only to specified nodes
DMessages replicate only to master
💡 Hint
Refer to the explanation in key moments about ha-mode policy effects.
Concept Snapshot
Mirrored queues replicate messages across nodes for redundancy.
Set policy with ha-mode=all to mirror on all nodes.
Master queue handles messages; mirrors keep copies.
If master fails, a mirror is promoted to master.
This ensures no message loss and high availability.
Full Transcript
Mirrored queues in RabbitMQ work by replicating messages from a master queue to mirror queues on other nodes. When a client sends a message, it arrives at the master queue and is copied to mirrors. Consumers read from the master queue normally. If the master node fails, one of the mirrors is promoted to master, allowing message consumption to continue without loss. This setup requires setting a policy with ha-mode=all to enable mirroring on all nodes. The execution trace shows queue states and message flow through publishing, consumption, failure, and recovery steps, illustrating how redundancy is maintained.