Bird
Raised Fist0
RabbitMQdevops~20 mins

Message durability and persistence in RabbitMQ - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Message Durability Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding message durability in RabbitMQ

Which statement best describes the role of message durability in RabbitMQ?

ADurable messages are stored only in memory and lost on broker restart.
BDurable messages survive broker restarts only if the queue is durable.
CDurable messages automatically replicate to all consumers.
DDurable messages are deleted immediately after being consumed.
Attempts:
2 left
💡 Hint

Think about what happens to messages when RabbitMQ restarts.

💻 Command Output
intermediate
2:00remaining
Result of publishing a non-persistent message to a durable queue

What happens when you publish a non-persistent message to a durable queue and then restart RabbitMQ?

RabbitMQ
rabbitmqadmin publish routing_key=test_queue payload='Hello' delivery_mode=1
# Then restart RabbitMQ server
AThe message is duplicated after restart.
BThe message is saved and delivered after restart.
CThe message is lost after restart.
DRabbitMQ throws an error on publishing.
Attempts:
2 left
💡 Hint

Consider what delivery_mode=1 means for message persistence.

❓ Configuration
advanced
2:00remaining
Correct queue declaration for durable message persistence

Which RabbitMQ queue declaration ensures messages are durable and survive broker restarts?

RabbitMQ
channel.queue_declare(queue='task_queue', durable=___)
ATrue
BFalse
CNone
D0
Attempts:
2 left
💡 Hint

Durable queues require a specific boolean value.

🔀 Workflow
advanced
2:00remaining
Ensuring message persistence in a RabbitMQ workflow

Which sequence of steps correctly ensures that messages are persistent and survive RabbitMQ restarts?

ADeclare queue with durable=True, publish messages with delivery_mode=2, restart broker
BDeclare queue with durable=True, publish messages with delivery_mode=1, restart broker
CDeclare queue with durable=False, publish messages with delivery_mode=2, restart broker
DDeclare queue with durable=False, publish messages with delivery_mode=1, restart broker
Attempts:
2 left
💡 Hint

Both queue and message must be durable for persistence.

❓ Troubleshoot
expert
2:00remaining
Diagnosing lost messages despite durable queue and persistent messages

You declared a durable queue and published messages with delivery_mode=2, but messages are lost after RabbitMQ restarts. What is the most likely cause?

AThe messages were published with the wrong routing key.
BThe messages were consumed before the restart, so none remained.
CThe RabbitMQ server was not properly restarted.
DThe queue was declared after messages were published, so it was recreated as non-durable.
Attempts:
2 left
💡 Hint

Consider the timing of queue declaration relative to message publishing.

Practice

(1/5)
1. What does setting a queue as durable in RabbitMQ ensure?
easy
A. The queue will only accept persistent messages.
B. Messages in the queue are automatically deleted after consumption.
C. The queue will survive a RabbitMQ server restart.
D. The queue will reject non-persistent messages.

Solution

  1. Step 1: Understand queue durability

    Setting a queue as durable means it will not be deleted when RabbitMQ restarts.
  2. Step 2: Differentiate from message persistence

    Durability affects the queue itself, not the messages inside it.
  3. Final Answer:

    The queue will survive a RabbitMQ server restart. -> Option C
  4. Quick Check:

    Durable queue = Survives restart [OK]
Hint: Durable queue means it stays after server restarts [OK]
Common Mistakes:
  • Confusing durable queue with persistent messages
  • Thinking durable queues delete messages automatically
  • Assuming durability rejects non-persistent messages
2. Which of the following is the correct way to declare a durable queue in RabbitMQ using the command line?
easy
A. rabbitmqadmin declare queue name=myqueue durable=true
B. rabbitmqadmin declare queue name=myqueue durable=1
C. rabbitmqadmin declare queue name=myqueue persistent=true
D. rabbitmqadmin declare queue name=myqueue durable

Solution

  1. Step 1: Check RabbitMQ CLI syntax for durable queues

    The correct syntax uses durable=true to declare a durable queue.
  2. Step 2: Eliminate incorrect options

    rabbitmqadmin declare queue name=myqueue durable=1 uses 1 instead of true, which is invalid. rabbitmqadmin declare queue name=myqueue persistent=true uses persistent which applies to messages, not queues. rabbitmqadmin declare queue name=myqueue durable is incomplete syntax.
  3. Final Answer:

    rabbitmqadmin declare queue name=myqueue durable=true -> Option A
  4. Quick Check:

    durable=true is correct syntax [OK]
Hint: Use durable=true to declare durable queues [OK]
Common Mistakes:
  • Using persistent instead of durable for queues
  • Using numeric values instead of true/false
  • Omitting the durable parameter
3. Given the following Python code snippet using pika library, what will happen if the message is sent with delivery_mode=2 but the queue is not durable?
channel.queue_declare(queue='task_queue', durable=False)
channel.basic_publish(
    exchange='',
    routing_key='task_queue',
    body='Hello World!',
    properties=pika.BasicProperties(delivery_mode=2))
medium
A. The message will be rejected by the queue due to mismatch in durability settings.
B. The message will be persistent but lost if RabbitMQ restarts because the queue is not durable.
C. The message will be persistent and survive RabbitMQ restarts regardless of queue durability.
D. The message will be lost immediately because delivery_mode=2 is invalid.

Solution

  1. Step 1: Understand message persistence with delivery_mode=2

    Setting delivery_mode=2 marks the message as persistent, meaning RabbitMQ will save it to disk.
  2. Step 2: Understand queue durability effect

    If the queue is not durable, it will be deleted on restart, so persistent messages in it will be lost.
  3. Final Answer:

    The message will be persistent but lost if RabbitMQ restarts because the queue is not durable. -> Option B
  4. Quick Check:

    Persistent message + non-durable queue = message lost on restart [OK]
Hint: Persistent messages need durable queues to survive restarts [OK]
Common Mistakes:
  • Assuming persistent messages survive without durable queues
  • Thinking delivery_mode=2 is invalid
  • Believing messages get rejected due to durability mismatch
4. You declared a queue as durable and sent messages with delivery_mode=2. After restarting RabbitMQ, messages are missing. What is the most likely cause?
medium
A. RabbitMQ does not support message persistence.
B. Messages were sent without the delivery_mode property.
C. The queue was deleted manually before restart.
D. The queue was declared as durable after it was first created as non-durable.

Solution

  1. Step 1: Check queue durability declaration timing

    If a queue is first created as non-durable, changing it to durable later has no effect unless the queue is deleted and recreated.
  2. Step 2: Understand message persistence requirements

    Messages with delivery_mode=2 are persistent, but if the queue is non-durable, messages are lost on restart.
  3. Final Answer:

    The queue was declared as durable after it was first created as non-durable. -> Option D
  4. Quick Check:

    Queue durability must be set at creation [OK]
Hint: Queue durability must be set when first created [OK]
Common Mistakes:
  • Assuming changing durability on existing queue works
  • Ignoring message delivery_mode settings
  • Believing RabbitMQ lacks persistence support
5. You want to ensure that messages are never lost even if RabbitMQ crashes or restarts. Which combination of settings should you use when declaring the queue and publishing messages?
hard
A. Declare the queue as durable and publish messages with delivery_mode=2.
B. Declare the queue as exclusive and publish messages with delivery_mode=1.
C. Declare the queue as auto-delete and publish messages with delivery_mode=2.
D. Declare the queue as durable and publish messages without specifying delivery_mode.

Solution

  1. Step 1: Understand durable queue role

    A durable queue survives RabbitMQ restarts, keeping the queue itself intact.
  2. Step 2: Understand persistent message role

    Messages with delivery_mode=2 are saved to disk, so they survive server crashes.
  3. Step 3: Combine both for full durability

    Only durable queues with persistent messages guarantee no message loss on restart.
  4. Final Answer:

    Declare the queue as durable and publish messages with delivery_mode=2. -> Option A
  5. Quick Check:

    Durable queue + persistent messages = no message loss [OK]
Hint: Use durable queues and delivery_mode=2 messages together [OK]
Common Mistakes:
  • Using exclusive or auto-delete queues for persistence
  • Not setting delivery_mode=2 for messages
  • Assuming durable queue alone is enough
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