TTL stands for Time To Live. It is the time a message can stay in a queue before it is discarded or dead-lettered.
Click to reveal answer
beginner
How do you set a message TTL for a queue in RabbitMQ?
You set the message TTL by adding the argument 'x-message-ttl' with a value in milliseconds when declaring the queue.
Click to reveal answer
beginner
What happens to a message when its TTL expires in RabbitMQ?
When a message's TTL expires, RabbitMQ removes it from the queue. It can be discarded or sent to a dead-letter exchange if configured.
Click to reveal answer
intermediate
Can you set TTL for individual messages in RabbitMQ?
Yes, you can set TTL for individual messages by adding the 'expiration' property in the message properties, specifying TTL in milliseconds.
Click to reveal answer
intermediate
What is the difference between queue TTL and message TTL in RabbitMQ?
Queue TTL ('x-message-ttl') sets the TTL for all messages in the queue. Message TTL ('expiration' property) sets TTL per message. The shorter TTL applies.
Click to reveal answer
What does setting 'x-message-ttl' on a queue do?
ASets how long the queue itself exists
BSets how long messages stay in the queue before expiring
CSets the maximum size of the queue
DSets the priority of messages in the queue
✗ Incorrect
The 'x-message-ttl' argument defines the time in milliseconds that messages can stay in the queue before they expire.
How can you set TTL for a single message in RabbitMQ?
ABy setting the 'expiration' property in the message properties
BBy setting 'x-message-ttl' on the queue
CBy setting the queue's max length
DBy setting the message priority
✗ Incorrect
Individual message TTL is set using the 'expiration' property in the message properties, specifying TTL in milliseconds.
What happens to a message after its TTL expires in RabbitMQ?
AIt is removed from the queue and discarded or dead-lettered
BIt is moved to the front of the queue
CIt is duplicated and sent to all consumers
DIt is archived for later processing
✗ Incorrect
Expired messages are removed from the queue and either discarded or sent to a dead-letter exchange if configured.
If both queue TTL and message TTL are set, which TTL applies?
ATTL settings are ignored
BOnly the queue TTL applies
CThe shorter TTL between queue and message TTL
DOnly the message TTL applies
✗ Incorrect
RabbitMQ applies the shorter TTL between the queue's 'x-message-ttl' and the message's 'expiration' property.
Which unit is used to specify TTL values in RabbitMQ?
AMinutes
BSeconds
CHours
DMilliseconds
✗ Incorrect
TTL values in RabbitMQ are specified in milliseconds.
Explain how message TTL works in RabbitMQ and how you can configure it.
Think about how long messages live and what happens when time runs out.
You got /4 concepts.
Describe the difference between queue-level TTL and message-level TTL in RabbitMQ.
Consider the scope of TTL settings and their priority.
You got /4 concepts.
Practice
(1/5)
1. What does setting a Message TTL (Time To Live) in RabbitMQ do?
easy
A. It sets the maximum size of a message in bytes.
B. It specifies the priority level of messages in the queue.
C. It controls the number of consumers allowed to read from a queue.
D. It defines how long a message stays in a queue before it is removed.
Solution
Step 1: Understand the purpose of Message TTL
Message TTL controls the lifetime of messages in a queue before they expire and get removed.
Step 2: Compare options with TTL definition
Only It defines how long a message stays in a queue before it is removed. correctly describes TTL as the time a message stays before removal.
Final Answer:
It defines how long a message stays in a queue before it is removed. -> Option D
Quick Check:
Message TTL = message lifetime in queue [OK]
Hint: TTL means message lifetime before removal [OK]
Common Mistakes:
Confusing TTL with message size limit
Thinking TTL controls consumer count
Mixing TTL with message priority
2. Which of the following is the correct way to set a queue-level message TTL of 60000 milliseconds in RabbitMQ using the policy command?
easy
A. rabbitmqctl set_policy TTL "^myqueue$" '{"message-ttl":60000}' --apply-to queues
B. rabbitmqctl set_policy TTL "myqueue" '{"message-ttl":60000}' --apply-to exchanges
C. rabbitmqctl set_policy TTL "^myqueue$" '{"queue-ttl":60000}' --apply-to queues
D. rabbitmqctl set_policy TTL "myqueue" '{"message-ttl":60}' --apply-to queues
Solution
Step 1: Identify correct policy syntax for message TTL
The policy command uses regex for queue names, JSON for arguments, and --apply-to queues for queue policies.
Step 2: Check each option's correctness
rabbitmqctl set_policy TTL "^myqueue$" '{"message-ttl":60000}' --apply-to queues uses regex ^myqueue$, correct key "message-ttl" with 60000 ms, and applies to queues. Others have wrong keys, apply-to exchanges, or wrong TTL units.
Final Answer:
rabbitmqctl set_policy TTL "^myqueue$" '{"message-ttl":60000}' --apply-to queues -> Option A
Quick Check:
Policy syntax with regex and message-ttl key [OK]
Hint: Use regex and 'message-ttl' key with --apply-to queues [OK]
Common Mistakes:
Using 'queue-ttl' instead of 'message-ttl'
Applying policy to exchanges instead of queues
Not using regex for queue name
3. Given the following queue declaration in RabbitMQ with a message TTL of 5000 ms:
What happens to a message published to this queue if it is not consumed within 6 seconds?
medium
A. The message remains in the queue indefinitely until consumed.
B. The message is removed from the queue after 5 seconds and will not be delivered.
C. The message is moved to a dead-letter queue immediately.
D. The message TTL resets every time a consumer connects.
Solution
Step 1: Understand x-message-ttl effect on messages
The 'x-message-ttl' argument sets how long messages live in the queue before expiring if not consumed.
Step 2: Analyze the timing and behavior
Since TTL is 5000 ms (5 seconds), a message not consumed within 6 seconds expires and is removed from the queue.
Final Answer:
The message is removed from the queue after 5 seconds and will not be delivered. -> Option B
Quick Check:
Message TTL 5000 ms means removal after 5 seconds [OK]
Hint: Message expires after TTL if not consumed [OK]
Common Mistakes:
Assuming message stays forever without consumer
Thinking TTL resets on consumer connection
Confusing dead-letter queue behavior
4. You set a message TTL of 10000 ms on a queue, but messages are not expiring as expected. Which of the following is the most likely cause?
medium
A. The queue was declared without the 'x-message-ttl' argument, so TTL is not applied.
B. The messages have individual TTLs that override the queue TTL with longer values.
C. The RabbitMQ server does not support message TTL feature.
D. The consumer is acknowledging messages too quickly.
Solution
Step 1: Understand common causes for TTL not applying
The most frequent issue is omitting the 'x-message-ttl' argument during queue declaration, despite intending to set it.
Step 2: Evaluate each option's likelihood
The queue was declared without the 'x-message-ttl' argument, so TTL is not applied. is most likely, as missing the argument prevents TTL enforcement. The messages have individual TTLs that override the queue TTL with longer values. is incorrect, as RabbitMQ uses the minimum TTL (queue wins if shorter). The RabbitMQ server does not support message TTL feature. is false. The consumer is acknowledging messages too quickly. causes consumption before expiration, not TTL failure.
Final Answer:
The queue was declared without the 'x-message-ttl' argument, so TTL is not applied. -> Option A
5. You want to configure a RabbitMQ queue so that messages expire after 10 seconds if not consumed, and expired messages are sent to a dead-letter exchange named dlx_exchange. Which queue arguments should you set?
hard
A. {"x-message-ttl": 10000, "x-dead-letter-exchange": ""}
B. {"x-queue-ttl": 10000, "x-dead-letter-exchange": "dlx_exchange"}
C. {"x-message-ttl": 10000, "x-dead-letter-exchange": "dlx_exchange"}
D. {"x-message-ttl": 10000, "x-dead-letter-routing-key": "dlx_exchange"}
Solution
Step 1: Identify correct TTL and dead-letter arguments
To expire messages after 10 seconds, use "x-message-ttl": 10000. To send expired messages to a dead-letter exchange, use "x-dead-letter-exchange" with the exchange name.
Step 2: Evaluate options for correctness
{"x-message-ttl": 10000, "x-dead-letter-exchange": "dlx_exchange"} correctly sets both "x-message-ttl" and "x-dead-letter-exchange". {"x-queue-ttl": 10000, "x-dead-letter-exchange": "dlx_exchange"} uses "x-queue-ttl" which expires the whole queue, not messages. {"x-message-ttl": 10000, "x-dead-letter-routing-key": "dlx_exchange"} misuses "x-dead-letter-routing-key" for exchange name. {"x-message-ttl": 10000, "x-dead-letter-exchange": ""} sets dead-letter exchange to empty string, disabling dead-lettering.
Final Answer:
{"x-message-ttl": 10000, "x-dead-letter-exchange": "dlx_exchange"} -> Option C
Quick Check:
Use x-message-ttl and x-dead-letter-exchange keys [OK]
Hint: Use x-message-ttl and x-dead-letter-exchange keys [OK]