Bird
Raised Fist0
RabbitMQdevops~20 mins

Queue TTL and auto-expiry in RabbitMQ - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
RabbitMQ TTL Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding Queue TTL behavior in RabbitMQ

What happens to messages in a RabbitMQ queue when the queue has a TTL (time-to-live) set on messages?

AMessages are moved to a dead-letter queue only if the TTL is set on the queue, not on messages.
BMessages expire and are removed from the queue after the TTL duration, even if they are not consumed.
CMessages are deleted immediately when the queue is declared with TTL, regardless of message age.
DMessages remain in the queue indefinitely until consumed, TTL only applies to the queue itself.
Attempts:
2 left
💡 Hint

Think about what TTL means for individual messages in a queue.

💻 Command Output
intermediate
1:30remaining
Queue auto-expiry effect on queue existence

Given a queue declared with x-expires set to 60000 (60 seconds), what happens if the queue is unused for 70 seconds?

RabbitMQ
rabbitmqctl list_queues name messages
# After 70 seconds of no consumers or messages
AThe queue is automatically deleted and will not appear in the list.
BThe queue remains but all messages inside expire.
CThe queue remains with zero messages but is not deleted.
DThe queue is paused and will not accept new messages.
Attempts:
2 left
💡 Hint

Consider what x-expires controls in RabbitMQ.

❓ Configuration
advanced
2:00remaining
Correct queue declaration with message TTL and auto-expiry

Which of the following queue declarations correctly sets a message TTL of 30 seconds and auto-expiry of 2 minutes?

Arabbitmqadmin declare queue name=myqueue arguments={"x-message-ttl":120000,"x-expires":30000}
Brabbitmqadmin declare queue name=myqueue arguments={"x-expires":30000,"x-message-ttl":120000}
Crabbitmqadmin declare queue name=myqueue arguments={"x-message-ttl":30000,"x-expires":120000}
Drabbitmqadmin declare queue name=myqueue arguments={"x-expires":60000,"x-message-ttl":60000}
Attempts:
2 left
💡 Hint

Remember TTL values are in milliseconds and x-message-ttl is for messages, x-expires is for queue expiry.

❓ Troubleshoot
advanced
2:00remaining
Diagnosing why messages are not expiring as expected

You set x-message-ttl to 10000 (10 seconds) on a queue, but messages remain indefinitely. What is the most likely cause?

AThe messages were published with individual TTLs overriding the queue TTL.
BThe queue has active consumers that keep messages from expiring.
CThe queue is a classic queue and does not support TTL.
DThe <code>x-message-ttl</code> argument was set on the queue but not on the messages.
Attempts:
2 left
💡 Hint

Consider how message TTLs interact with queue TTL settings.

🔀 Workflow
expert
2:30remaining
Sequence to configure and verify queue TTL and auto-expiry

Arrange the steps in the correct order to configure a RabbitMQ queue with message TTL and auto-expiry, then verify the settings.

A2,1,3,4
B3,1,2,4
C1,3,2,4
D1,2,3,4
Attempts:
2 left
💡 Hint

Think about what must happen before publishing messages and verifying settings.

Practice

(1/5)
1. What does setting a x-message-ttl on a RabbitMQ queue do?
easy
A. It sets how long messages stay in the queue before they expire.
B. It deletes the queue after a certain time of inactivity.
C. It limits the number of messages the queue can hold.
D. It changes the priority of messages in the queue.

Solution

  1. Step 1: Understand x-message-ttl meaning

    The x-message-ttl setting controls the time-to-live for messages in the queue, meaning how long each message can stay before expiring.
  2. Step 2: Differentiate from queue auto-expiry

    Queue auto-expiry deletes the entire queue after inactivity, which is different from message TTL.
  3. Final Answer:

    It sets how long messages stay in the queue before they expire. -> Option A
  4. Quick Check:

    Message TTL = message lifetime [OK]
Hint: Message TTL controls message lifetime, not queue deletion [OK]
Common Mistakes:
  • Confusing message TTL with queue auto-expiry
  • Thinking TTL limits message count
  • Assuming TTL changes message priority
2. Which of the following is the correct way to set a queue TTL of 60000 milliseconds in RabbitMQ using arguments?
easy
A. {"x-message-ttl":60000}
B. {"x-expires":60000}
C. {"x-max-length":60000}
D. {"x-priority":60000}

Solution

  1. Step 1: Identify the correct argument for message TTL

    The argument x-message-ttl is used to set the time-to-live for messages in milliseconds.
  2. Step 2: Verify other options

    x-expires is for queue auto-expiry, x-max-length limits queue size, and x-priority sets message priority, so they are incorrect here.
  3. Final Answer:

    {"x-message-ttl":60000} -> Option A
  4. Quick Check:

    TTL argument = x-message-ttl [OK]
Hint: Use x-message-ttl for message expiry time in ms [OK]
Common Mistakes:
  • Using x-expires instead of x-message-ttl
  • Confusing max-length with TTL
  • Setting priority instead of TTL
3. Given a queue with x-message-ttl set to 30000 ms and a message published at time 0, what happens if the message is not consumed by 35000 ms?
medium
A. The queue is deleted after 30000 ms.
B. The message is removed from the queue automatically after 30000 ms.
C. The message stays in the queue indefinitely until consumed.
D. The message priority is increased after 30000 ms.

Solution

  1. Step 1: Understand message TTL effect

    Message TTL of 30000 ms means messages expire and are removed if not consumed within 30 seconds.
  2. Step 2: Apply timing to message

    Since the message is not consumed by 35000 ms (which is after 30000 ms), it will be removed automatically.
  3. Final Answer:

    The message is removed from the queue automatically after 30000 ms. -> Option B
  4. Quick Check:

    Message expires after TTL [OK]
Hint: Messages expire after TTL if not consumed [OK]
Common Mistakes:
  • Thinking messages stay forever without consumption
  • Confusing message TTL with queue deletion
  • Assuming priority changes with TTL
4. You set x-expires to 60000 on a queue, but the queue is not deleted after 1 minute of inactivity. What could be the reason?
medium
A. The x-expires value must be set in seconds, not milliseconds.
B. RabbitMQ does not support queue auto-expiry.
C. The queue TTL must be set for the queue to expire.
D. The queue has active consumers or unacknowledged messages.

Solution

  1. Step 1: Understand x-expires behavior

    x-expires deletes the queue after the specified time of inactivity, meaning no consumers and no unacknowledged messages.
  2. Step 2: Identify why queue is not deleted

    If the queue has active consumers or unacknowledged messages, it is considered active and will not be deleted despite x-expires.
  3. Final Answer:

    The queue has active consumers or unacknowledged messages. -> Option D
  4. Quick Check:

    Queue expires only if inactive [OK]
Hint: Queue expires only when fully inactive (no consumers) [OK]
Common Mistakes:
  • Confusing milliseconds with seconds for x-expires
  • Thinking message TTL controls queue expiry
  • Believing RabbitMQ lacks auto-expiry feature
5. You want a queue to automatically delete itself if unused for 2 minutes and also want messages to expire after 1 minute. Which configuration is correct?
hard
A. {"x-max-length":120000, "x-expires":60000}
B. {"x-message-ttl":120000, "x-expires":60000}
C. {"x-expires":120000, "x-message-ttl":60000}
D. {"x-expires":60000, "x-message-ttl":120000}

Solution

  1. Step 1: Match time values to correct arguments

    x-expires controls queue auto-expiry after inactivity, so 2 minutes = 120000 ms should be set here. x-message-ttl controls message expiry, so 1 minute = 60000 ms goes here.
  2. Step 2: Verify option correctness

    {"x-expires":120000, "x-message-ttl":60000} correctly assigns x-expires to 120000 and x-message-ttl to 60000. Other options swap or misuse these values.
  3. Final Answer:

    {"x-expires":120000, "x-message-ttl":60000} -> Option C
  4. Quick Check:

    Queue expiry = 120000 ms, Message TTL = 60000 ms [OK]
Hint: Set x-expires for queue, x-message-ttl for messages [OK]
Common Mistakes:
  • Swapping TTL and expires values
  • Using max-length instead of TTL or expires
  • Confusing milliseconds with seconds
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