Bird
Raised Fist0
RabbitMQdevops~10 mins

Message durability and persistence in RabbitMQ - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a durable queue in RabbitMQ.

RabbitMQ
channel.queue_declare(queue='task_queue', durable=[1])
Drag options to blanks, or click blank then click option'
AFalse
BTrue
C'yes'
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of a boolean
Setting durable to False
2fill in blank
medium

Complete the code to publish a persistent message to a queue.

RabbitMQ
channel.basic_publish(exchange='', routing_key='task_queue', body=message, properties=pika.BasicProperties(delivery_mode=[1]))
Drag options to blanks, or click blank then click option'
A1
B0
C2
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using delivery_mode=1 which is non-persistent
Using delivery_mode=0 which is invalid
3fill in blank
hard

Fix the error in the code to ensure both queue and messages are durable.

RabbitMQ
channel.queue_declare(queue='task_queue', durable=[1])
channel.basic_publish(exchange='', routing_key='task_queue', body=message, properties=pika.BasicProperties(delivery_mode=[2]))
Drag options to blanks, or click blank then click option'
AFalse
BTrue
C1
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up delivery_mode values
Not setting queue durable to True
4fill in blank
hard

Fill both blanks to declare a durable queue and publish a persistent message with correct properties.

RabbitMQ
channel.queue_declare(queue='[1]', durable=[2])
channel.basic_publish(exchange='', routing_key='[1]', body=msg, properties=pika.BasicProperties(delivery_mode=2))
Drag options to blanks, or click blank then click option'
Atask_queue
BFalse
CTrue
Dlogs
Attempts:
3 left
💡 Hint
Common Mistakes
Using different queue names
Setting durable to False
5fill in blank
hard

Fill all three blanks to declare a durable queue, publish a persistent message, and set message expiration to 60000 ms.

RabbitMQ
channel.queue_declare(queue='[1]', durable=[2])
channel.basic_publish(exchange='', routing_key='[1]', body=msg, properties=pika.BasicProperties(delivery_mode=[3], expiration='60000'))
Drag options to blanks, or click blank then click option'
Atask_queue
BTrue
C2
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using delivery_mode other than 2
Setting durable to False
Mismatched queue names

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