Learn Labs
Failure Handling

Flow Control & Limits

Memory and disk alarms, blocked publishers, queue length limits, and backpressure

When consumers fall behind, messages pile up, and something has to give. RabbitMQ protects itself in layers: length limits on individual queues, per-connection flow control, and, as a last resort, resource alarms that stop every publisher in the cluster.

Resource alarms

Two thresholds, set in config/rabbitmq.conf:

vm_memory_high_watermark.relative = 0.6alarm when the node uses 60% of its memory limitdisk_free_limit.absolute = 1GBalarm when free disk drops below 1 GB

When either is crossed on any node, RabbitMQ blocks every publishing connection in the cluster until it clears. Consumers keep working, which is what lets the backlog drain.

also blockedpublisher Ablockedpublisher Bblockedrabbit-1memory alarmrabbit-2healthyconsumerskeep drainingan alarm on any node blocks publishing cluster-wide until the backlog drains

Triggered on purpose in this lab by lowering the watermark:

docker exec rabbit-1 rabbitmqctl set_vm_memory_high_watermark 0.0001
docker exec rabbit-1 rabbitmq-diagnostics -q alarms
Memory alarm on node rabbit@rabbit-1

# a publisher that registered a callback is told why:
conn.add_on_connection_blocked_callback(lambda c, m: print(m.method.reason))
blocked callback: ['low on memory']

docker exec rabbit-1 rabbitmqctl set_vm_memory_high_watermark 0.6      # restore
Node rabbit@rabbit-1 reported no alarms, local or clusterwide

set_vm_memory_high_watermark changes the threshold at runtime only; the config file value returns on restart. In containers, RabbitMQ detects the cgroup memory limit (mem_limit: 1g here) and calculates the watermark from that.

Per-connection flow control

Before alarms, there's a gentler mechanism: if a queue can't keep up with a publisher, RabbitMQ slows that publisher's connection using internal credit (the connection shows state flow in the UI). It's automatic and mostly invisible, a sign that something downstream is the bottleneck.

Queue length limits

Bound individual queues so one runaway producer can't fill the node:

x-max-length: 10000messages (or policy: max-length)x-max-length-bytes: 100000000bytesx-overflow: drop-headdefault: discard (or dead-letter) the OLDEST messagesx-overflow: reject-publishrefuse new publishes (nack with confirms)x-overflow: reject-publish-dlxrefuse, and dead-letter the refused message (classic queues)
OverflowGood for
drop-headLatest-value feeds where old messages are worthless (prices, sensor readings)
reject-publishWork that must not be silently lost: publishers see nacks and back off

The lab-limits policy in definitions.json caps every lab.* queue at 100,000 messages with reject-publish. As Publisher Confirms showed, quorum queues enforce limits asynchronously, so a fast burst can overshoot, and without confirms the publisher never learns which messages were refused.

Message TTL

x-message-ttl: 60000queue-wide: messages expire after 60 s (or policy: message-ttl)expiration: "60000"per message, a string, set by the publisherx-expires: 1800000the QUEUE is deleted after 30 min unused

Expired messages are dropped, or dead-lettered with reason expired if the queue has a DLX, the basis of delayed retries.

Backpressure, end to end

Lab

  1. Reproduce the memory alarm with set_vm_memory_high_watermark 0.0001. Run reliability.py while it's active and watch it hang. Restore the watermark and watch it continue.
  2. Declare a queue with x-max-length: 5 and default overflow, publish 10, and read what's left. Which 5 survived?
  3. Repeat with reject-publish and publisher confirms.
  4. Set a policy message-ttl: 5000 on tmp.* queues, publish to tmp.test, and watch the messages expire in the UI.

On this page