📖 Scenario: You are setting up a RabbitMQ message broker for a small company. To ensure messages are not lost if one server fails, you want to create a mirrored queue. This queue will copy messages to multiple servers automatically.
🎯 Goal: Learn how to create a mirrored queue in RabbitMQ by defining a policy that replicates the queue across nodes for redundancy.
📋 What You'll Learn
Create a queue named task_queue
Define a policy named ha-all to mirror task_queue across all nodes
Apply the policy with the correct pattern and arguments
Verify the policy is applied and the queue is mirrored
💡 Why This Matters
🌍 Real World
Mirrored queues ensure message safety in distributed systems by replicating messages across multiple servers. This prevents data loss if one server crashes.
💼 Career
Understanding mirrored queues is important for DevOps engineers managing message brokers in production environments to maintain high availability and fault tolerance.
Progress0 / 4 steps
1
Create the queue task_queue
Use the RabbitMQ command line tool to create a queue named task_queue on the default virtual host.
RabbitMQ
Hint
Use rabbitmqadmin declare queue with name=task_queue and durable=true to create the queue.
2
Define a policy ha-all to mirror task_queue
Create a policy named ha-all that matches the queue task_queue and sets the argument ha-mode to all to mirror the queue on all nodes.
RabbitMQ
Hint
Use rabbitmqctl set_policy with the name ha-all, pattern ^task_queue$, and argument {"ha-mode":"all"}.
3
Verify the policy is applied to task_queue
Use the RabbitMQ command line to list all policies and confirm that the policy ha-all is applied to task_queue.
RabbitMQ
Hint
Use rabbitmqctl list_policies to see all policies and check for ha-all.
4
Show the final output confirming the policy
Run the command to list policies and print the output showing the ha-all policy applied to task_queue.
RabbitMQ
Hint
The output should list the ha-all policy with pattern ^task_queue$ and argument {"ha-mode":"all"}.
Practice
(1/5)
1. What is the main purpose of using mirrored queues in RabbitMQ?
easy
A. To keep copies of messages on multiple servers for safety
B. To speed up message delivery by duplicating messages
C. To reduce the number of messages stored in the queue
D. To encrypt messages automatically during transmission
Solution
Step 1: Understand mirrored queues concept
Mirrored queues replicate messages across multiple RabbitMQ nodes to ensure no message is lost if one node fails.
Step 2: Identify the main benefit
This replication provides redundancy and safety, not speed or encryption.
Final Answer:
To keep copies of messages on multiple servers for safety -> Option A
Quick Check:
Mirroring = Redundancy and safety [OK]
Hint: Mirrored queues copy messages for safety, not speed or encryption [OK]
Common Mistakes:
Thinking mirroring speeds up delivery
Confusing mirroring with encryption
Assuming mirroring reduces message count
2. Which command correctly sets a policy to mirror all queues in RabbitMQ?
easy
A. rabbitmqctl set_policy ha-all .* '{"ha-mode":"all"}'
B. rabbitmqctl set_policy ha-all ".*" '{"ha-mode":"all"}'
C. rabbitmqctl set_policy ha-all ".*" '{ha-mode:all}'
D. rabbitmqctl set_policy ha-all ".*" '{"ha-mode":all}'
Solution
Step 1: Review correct syntax for set_policy
The command requires the policy name, pattern in quotes, and JSON string with keys and values in double quotes.
Step 2: Identify correct JSON format and quoting
rabbitmqctl set_policy ha-all ".*" '{"ha-mode":"all"}' uses correct JSON with double quotes around keys and values and quotes the pattern ".*" properly.
Final Answer:
rabbitmqctl set_policy ha-all ".*" '{"ha-mode":"all"}' -> Option B
Hint: ha-mode 'exactly' with ha-params sets mirror count [OK]
Common Mistakes:
Confusing 'all' with 'exactly'
Ignoring ha-params value
Assuming no mirroring without ha-mode 'all'
4. You set this policy: rabbitmqctl set_policy ha-all ".*" '{"ha-mode":"all"}' But queues are not mirrored. What is the likely problem?
medium
A. The policy requires a restart of the queue or server to apply
B. The pattern ".*" does not match queue names
C. The policy was set but RabbitMQ was not restarted
D. The JSON syntax is incorrect
Solution
Step 1: Check policy application behavior
Policies apply only to new queues or queues restarted after policy set.
Step 2: Identify why existing queues are not mirrored
Existing queues created before policy need to be deleted or restarted to apply mirroring.
Final Answer:
The policy requires a restart of the queue or server to apply -> Option A
Quick Check:
Policy applies only on new or restarted queues [OK]
Hint: Policies apply only to new or restarted queues [OK]
Common Mistakes:
Thinking RabbitMQ restart is needed
Assuming pattern ".*" never matches
Believing JSON syntax is wrong when it is correct
5. You want to ensure a queue named task_queue is mirrored on at least 3 nodes but no more than 5 using a range specification in ha-params. Which policy configuration achieves this?
hard
A. rabbitmqctl set_policy ha-range "^task_queue$" '{"ha-mode":"nodes","ha-params":["node1","node2","node3"]}'
B. rabbitmqctl set_policy ha-minmax ".*" '{"ha-mode":"exactly","ha-params":3}'
C. rabbitmqctl set_policy ha-minmax "^task_queue$" '{"ha-mode":"nodes","ha-params":["node1","node2","node3","node4","node5"]}'
D. rabbitmqctl set_policy ha-minmax "^task_queue$" '{"ha-mode":"exactly","ha-params":"3-5"}'
Solution
Step 1: Understand ha-mode 'exactly' with range ha-params
ha-mode 'exactly' with ha-params as string like '3-5' dynamically mirrors the queue on a number of replicas between 3 and 5.
Step 2: Identify correct command
rabbitmqctl set_policy ha-minmax "^task_queue$" '{"ha-mode":"exactly","ha-params":"3-5"}' matches the queue exactly and uses range specification.
Step 3: Check other options
B uses fixed exactly 3 on all queues; C uses fixed nodes list of 5; D uses fixed nodes list of 3.
Final Answer:
rabbitmqctl set_policy ha-minmax "^task_queue$" '{"ha-mode":"exactly","ha-params":"3-5"}' -> Option D
Quick Check:
ha-mode exactly + ha-params "3-5" = dynamic range 3-5 [OK]
Hint: Use ha-mode 'exactly' with ha-params "3-5" for range [OK]
Common Mistakes:
Using 'exactly' with fixed integer instead of range string
Not matching queue name exactly
Using 'nodes' mode with fixed list instead of range
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.