Configure Message TTL and Queue Length Limits
Use message TTL and queue length limits to keep queue growth within a controlled window. These settings are useful for burst handling, standby backlog control, and queues that should not retain stale messages forever.
Prefer policies over hard-coded queue arguments when the same limits must apply to multiple queues or when you want to adjust limits without redeclaring queues.
TOC
Choose the Correct ControlApply a Queue PolicyVerify the Active PolicyDesign RecommendationsRelated InformationChoose the Correct Control
Queue expiration deletes an unused queue. Message TTL expires messages. For durable application queues and warm-standby queues, use message-ttl for backlog control and avoid expires unless the queue is intentionally temporary.
Apply a Queue Policy
The following example applies a 24-hour message retention window and queue length limits to queues that start with orders. in the default virtual host:
In this example:
- Messages older than 24 hours become eligible for expiration.
- The queue holds at most 100000 messages.
- The queue holds at most 1 GiB of message data.
- New publishes are rejected after the limit is reached and can be dead-lettered if the queue is configured with a DLX.
If another policy already matches the same queues, review policy priorities before creating a competing rule.
Verify the Active Policy
List policies in the virtual host:
Verify the queue arguments and active policy:
Design Recommendations
- Use
message-ttlto bound standby or replay queues that should not grow forever. - Use
max-lengthormax-length-byteson high-volume queues so unexpected consumer outages do not exhaust disk. - Choose
overflow="reject-publish"oroverflow="reject-publish-dlx"when publishers must receive backpressure instead of silently losing the oldest messages. - Use
overflow="drop-head"only when the application explicitly prefers the newest messages over the oldest backlog. - Review limit values against traffic peaks, expected outage windows, and available storage.