0
0
RabbitMQdevops~30 mins

Queue TTL and auto-expiry in RabbitMQ - Mini Project: Build & Apply

Choose your learning style9 modes available
Queue TTL and Auto-Expiry in RabbitMQ
📖 Scenario: You are managing a messaging system using RabbitMQ. Some queues should automatically delete themselves if they are unused for a certain time. Also, messages in these queues should expire after a set time to avoid processing stale data.
🎯 Goal: Set up a RabbitMQ queue with a message TTL (time-to-live) of 10 seconds and an auto-expiry of 30 seconds. Then verify the queue auto-deletes after being unused.
📋 What You'll Learn
Create a queue named temp_queue with message TTL set to 10000 milliseconds
Set the queue's auto-expiry to 30000 milliseconds
Use RabbitMQ's rabbitmqadmin or rabbitmqctl commands to create and inspect the queue
Verify the queue is created with the correct TTL and auto-expiry settings
Observe the queue auto-delete after 30 seconds of inactivity
💡 Why This Matters
🌍 Real World
Queues with TTL and auto-expiry help keep messaging systems clean by removing old messages and unused queues automatically.
💼 Career
Understanding queue TTL and auto-expiry is important for DevOps roles managing message brokers to ensure efficient resource use and system reliability.
Progress0 / 4 steps
1
Create a queue with message TTL
Use the rabbitmqadmin declare queue command to create a queue named temp_queue with the argument x-message-ttl set to 10000 (10 seconds).
RabbitMQ
Need a hint?

Use the arguments parameter with JSON to set x-message-ttl.

2
Add auto-expiry to the queue
Modify the queue declaration command to add the argument x-expires set to 30000 (30 seconds) along with x-message-ttl.
RabbitMQ
Need a hint?

Include both x-message-ttl and x-expires in the arguments JSON.

3
Verify the queue settings
Use the rabbitmqctl list_queues name arguments command and filter for temp_queue to check that x-message-ttl and x-expires are set correctly.
RabbitMQ
Need a hint?

Use rabbitmqctl list_queues name arguments and look for temp_queue in the output.

4
Observe queue auto-expiry
Wait for 35 seconds without using the queue, then run rabbitmqctl list_queues name to confirm that temp_queue has been auto-deleted.
RabbitMQ
Need a hint?

Use sleep 35 to wait, then check if the queue is gone.