Bird
Raised Fist0
RabbitMQdevops~5 mins

Quorum queues (recommended) in RabbitMQ - Commands & Configuration

Choose your learning style10 modes available
Introduction
Quorum queues in RabbitMQ help keep your messages safe even if some servers fail. They do this by copying messages across multiple servers, so your data is not lost if one server goes down.
When you want to make sure messages are not lost during server crashes.
When you need a reliable queue that can handle server restarts without losing data.
When you want to replace classic mirrored queues with a more stable and easier to manage option.
When your application requires high availability and data safety for message delivery.
When you want automatic recovery of queues after network or server failures.
Config File - quorum-queue-policy.json
quorum-queue-policy.json
{
  "policies": [
    {
      "name": "quorum-queue-policy",
      "pattern": "^quorum-",
      "definition": {
        "queue-type": "quorum"
      },
      "priority": 1,
      "apply-to": "queues"
    }
  ]
}

This JSON file defines a policy for RabbitMQ that applies to all queues starting with 'quorum-'. It sets their type to 'quorum', which means these queues will use the quorum queue mechanism for better reliability and data safety.

The pattern key matches queue names, definition sets the queue type, priority decides the policy's importance, and apply-to specifies it applies to queues.

Commands
This command creates a policy named 'quorum-queue-policy' that matches all queues starting with 'quorum-' and sets their type to quorum. This ensures those queues use the quorum mechanism for reliability.
Terminal
rabbitmqctl set_policy quorum-queue-policy "^quorum-" '{"queue-type":"quorum"}' --priority 1 --apply-to queues
Expected OutputExpected
Setting policy "quorum-queue-policy" for pattern "^quorum-" to "{\"queue-type\":\"quorum\"}" with priority 1
→
--priority 1 - Sets the priority of this policy to 1 to override lower priority policies
→
--apply-to queues - Applies this policy only to queues, not exchanges
This command creates a new durable queue named 'quorum-myqueue'. Because of the policy, this queue will be a quorum queue, ensuring message safety and replication.
Terminal
rabbitmqadmin declare queue name=quorum-myqueue durable=true
Expected OutputExpected
{ "name": "quorum-myqueue", "vhost": "/", "durable": true, "auto_delete": false, "arguments": {}, "node": "rabbit@localhost" }
This command lists all queues with their names, types, and durability. It helps verify that 'quorum-myqueue' is created as a quorum queue and is durable.
Terminal
rabbitmqctl list_queues name type durable
Expected OutputExpected
Listing queues ... quorum-myqueue quorum true
This command removes the 'quorum-queue-policy' policy. Use this if you want to stop applying quorum queue settings to matching queues.
Terminal
rabbitmqctl clear_policy quorum-queue-policy
Expected OutputExpected
Cleared policy "quorum-queue-policy"
Key Concept

If you remember nothing else from quorum queues, remember: they replicate messages safely across servers to prevent data loss during failures.

Common Mistakes
Creating queues without the policy and expecting them to be quorum queues.
Queues default to classic type unless a policy or argument sets them to quorum, so they won't have replication or safety features.
Always create a policy that sets 'queue-type' to 'quorum' for queues you want to be quorum queues, or specify the type when declaring the queue.
Using non-durable queues with quorum type.
Quorum queues require durability to ensure messages survive server restarts; non-durable queues lose messages on restart.
Always declare quorum queues with durable=true to keep messages safe.
Not verifying queue type after creation.
Without checking, you might think your queue is quorum but it could be classic, missing replication benefits.
Use 'rabbitmqctl list_queues' to confirm the queue type is 'quorum' after creation.
Summary
Set a policy to mark queues starting with 'quorum-' as quorum queues for replication and safety.
Create durable queues that match the policy to get quorum queue benefits.
Verify queue type with 'rabbitmqctl list_queues' to ensure correct setup.

Practice

(1/5)
1. What is the main purpose of a quorum queue in RabbitMQ?
easy
A. To replicate messages across multiple nodes for safety
B. To speed up message delivery by using a single node
C. To store messages only on disk without replication
D. To limit the number of messages in the queue

Solution

  1. Step 1: Understand quorum queue purpose

    Quorum queues replicate messages to multiple nodes to ensure safety and durability.
  2. Step 2: Compare options

    Only To replicate messages across multiple nodes for safety describes replication for safety, which is the main feature of quorum queues.
  3. Final Answer:

    To replicate messages across multiple nodes for safety -> Option A
  4. Quick Check:

    Quorum queue purpose = replication for safety [OK]
Hint: Quorum queues replicate messages for safety [OK]
Common Mistakes:
  • Thinking quorum queues speed up delivery instead of ensuring safety
  • Confusing quorum queues with simple disk storage
  • Assuming quorum queues limit message count
2. Which is the correct way to declare a quorum queue in RabbitMQ using the CLI?
easy
A. rabbitmqadmin declare queue name=myqueue durable=true arguments={"x-queue-type":"quorum"}
B. rabbitmqadmin declare queue name=myqueue durable=true
C. rabbitmqctl add_queue myqueue x-queue-type=classic
D. rabbitmqctl add_queue myqueue durable=true

Solution

  1. Step 1: Identify quorum queue declaration syntax

    Quorum queues require setting the argument "x-queue-type" to "quorum" when declaring the queue.
  2. Step 2: Check options for correct syntax

    Only rabbitmqadmin declare queue name=myqueue durable=true arguments={"x-queue-type":"quorum"} uses the correct syntax with rabbitmqadmin and sets the argument properly.
  3. Final Answer:

    rabbitmqadmin declare queue name=myqueue durable=true arguments={"x-queue-type":"quorum"} -> Option A
  4. Quick Check:

    Quorum queue declaration = set x-queue-type to quorum [OK]
Hint: Set x-queue-type to quorum in queue arguments [OK]
Common Mistakes:
  • Using rabbitmqctl add_queue which is not a valid command
  • Not setting x-queue-type argument
  • Using classic queue type instead of quorum
3. Given the following command, what will be the type of the queue created?
rabbitmqadmin declare queue name=test durable=true arguments={"x-queue-type":"quorum"}
medium
A. Classic queue
B. Lazy queue
C. Priority queue
D. Quorum queue

Solution

  1. Step 1: Analyze the queue declaration command

    The command sets the argument "x-queue-type" to "quorum", which specifies the queue type.
  2. Step 2: Determine queue type from argument

    Setting "x-queue-type" to "quorum" creates a quorum queue.
  3. Final Answer:

    Quorum queue -> Option D
  4. Quick Check:

    Queue type argument = quorum [OK]
Hint: Check x-queue-type argument value for queue type [OK]
Common Mistakes:
  • Assuming default classic queue without checking arguments
  • Confusing quorum with lazy or priority queues
  • Ignoring the arguments field
4. You tried to create a quorum queue but got an error. Which of these is the most likely cause?
medium
A. You declared the queue with a name longer than 10 characters
B. You set durable to false
C. You forgot to set the argument x-queue-type to quorum
D. You used the command rabbitmqctl add_queue

Solution

  1. Step 1: Identify required argument for quorum queues

    Quorum queues require the argument "x-queue-type" set to "quorum"; missing this causes errors.
  2. Step 2: Evaluate other options

    Durability false is allowed, rabbitmqctl add_queue is invalid command but not the main cause, and queue name length is not restricted to 10 characters.
  3. Final Answer:

    You forgot to set the argument x-queue-type to quorum -> Option C
  4. Quick Check:

    Missing x-queue-type=quorum causes error [OK]
Hint: Always set x-queue-type=quorum for quorum queues [OK]
Common Mistakes:
  • Assuming durability must be true
  • Using invalid rabbitmqctl commands
  • Believing queue name length causes errors
5. You want to ensure your important messages are never lost even if a RabbitMQ node crashes. Which queue type and setting should you use?
hard
A. Classic queue with durable=false
B. Quorum queue with x-queue-type set to quorum and durable=true
C. Lazy queue with auto-delete=true
D. Classic queue with exclusive=true

Solution

  1. Step 1: Identify queue type for message safety

    Quorum queues replicate messages across nodes, protecting against node crashes.
  2. Step 2: Check durability setting

    Durable=true ensures messages survive broker restarts, important for message safety.
  3. Step 3: Evaluate other options

    Classic queues with durable=false or exclusive=true do not guarantee safety; lazy queues with auto-delete=true remove queues automatically.
  4. Final Answer:

    Quorum queue with x-queue-type set to quorum and durable=true -> Option B
  5. Quick Check:

    Quorum + durable=true = message safety [OK]
Hint: Use quorum queue with durable=true for safety [OK]
Common Mistakes:
  • Using classic queues without durability
  • Confusing lazy or exclusive queues with safety features
  • Ignoring durable setting
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard