0
0
RabbitMQdevops~10 mins

Message TTL (Time To Live) in RabbitMQ - Interactive Code Practice

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

Complete the code to set a message TTL of 60000 milliseconds in a queue declaration.

RabbitMQ
channel.queue_declare(queue='task_queue', arguments=[1])
Drag options to blanks, or click blank then click option'
A{'x-expires': 60000}
B{'x-max-length': 60000}
C{'x-message-ttl': 60000}
D{'x-dead-letter-exchange': 'dlx'}
Attempts:
3 left
💡 Hint
Common Mistakes
Using x-expires instead of x-message-ttl sets queue expiration, not message TTL.
Confusing x-max-length with TTL; it limits queue size, not message lifetime.
2fill in blank
medium

Complete the code to publish a message with a TTL of 30000 milliseconds.

RabbitMQ
channel.basic_publish(exchange='', routing_key='task_queue', body='Hello', properties=pika.BasicProperties(expiration=[1]))
Drag options to blanks, or click blank then click option'
A30
B30000
C'30s'
D'30000'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing an integer instead of a string causes the TTL to be ignored.
Using time units like '30s' is invalid; TTL must be milliseconds as string.
3fill in blank
hard

Fix the error in the queue declaration to correctly set message TTL to 45000 milliseconds.

RabbitMQ
channel.queue_declare(queue='logs', arguments=[1])
Drag options to blanks, or click blank then click option'
A{'x-message-ttl': 45}
B{'x-message-ttl': 45000}
C{'x-message-ttl': '45000'}
D{'x-message-ttl': 450000}
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of an integer for TTL.
Setting TTL to 45 (too short) or 450000 (too long) by mistake.
4fill in blank
hard

Fill both blanks to declare a queue with message TTL of 20000 ms and dead-letter exchange named 'dlx'.

RabbitMQ
channel.queue_declare(queue='orders', arguments=[1])
Drag options to blanks, or click blank then click option'
A{'x-message-ttl': 20000, 'x-dead-letter-exchange': 'dlx'}
B{}
C{'x-dead-letter-exchange': 'dlx'}
D{'x-message-ttl': 20000}
Attempts:
3 left
💡 Hint
Common Mistakes
Setting only one of the two arguments.
Using empty or incomplete dictionaries.
5fill in blank
hard

Fill all three blanks to publish a persistent message with TTL 15000 ms to exchange 'logs' with routing key 'info'.

RabbitMQ
channel.basic_publish(exchange=[1], routing_key=[2], body='Log entry', properties=pika.BasicProperties(delivery_mode=[3], expiration='15000'))
Drag options to blanks, or click blank then click option'
A'logs'
B'info'
C2
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using delivery_mode 1 which is non-persistent.
Forgetting quotes around exchange or routing key.