RabbitMQ¶
Scope: designing exchanges, queues, publishers and consumers for RabbitMQ 4.x, following the current (4.4) documentation. Shared messaging rules aren't repeated here: publish events together with database changes through a transactional outbox (DATA-4, general/data.md), make operations safe to retry (API-1, general/api-design.md), buffer load with queues and retry with backoff (OPS-7, OPS-3, general/operations-reliability.md), and say which event-driven pattern you mean (STYLE-8 to STYLE-10, general/architecture-styles.md). For a log-based broker, see Apache Kafka; for secrets and least privilege, see general/security.md.
Entries are sorted by score from 1 to 10 (criteria): 9โ10 start here or strongly recommended, 6โ8 recommended, 1โ5 further reading or conditional.
Adopted references¶
- 9 RabbitMQ documentation (RabbitMQ 4.4): the baseline. The guides on queue types, publishers, consumers, acknowledgements and confirms, dead lettering, access control, TLS and monitoring matter most for application work.
- 8 Production Deployment Guidelines (RabbitMQ docs): the production checklist for storage, virtual hosts and users, resource limits, security, cluster size, and connection management in applications. Go through it before going live.
- 8 Reliability Guide (RabbitMQ docs): what can fail, and how publisher confirms, acknowledgements, heartbeats, clustering and replicated queues protect messages on the publisher, broker and consumer sides.
- 8 Consumer Acknowledgements and Publisher Confirms (RabbitMQ docs): acknowledgement modes, requeueing, prefetch and its effect on throughput, and when the broker confirms a published message.
- 7 Quorum Queues (RabbitMQ docs): when to use replicated quorum queues and when not, how they differ from classic queues, poison message handling, delayed retry and replication.
- 7 Streams and Superstreams (RabbitMQ docs): replicated append-only logs for large fan-outs, replay, high throughput and large backlogs, with retention and partitioned super streams.
- 7 Monitoring (RabbitMQ docs): monitoring with Prometheus and Grafana, the key node and queue metrics, and health checks in stages.
Key rules¶
Queues and data safety¶
- 9
RABBITMQ-2Publish with publisher confirms, and consume with manual acknowledgements, acknowledging each message only after it has been processed. With automatic acknowledgements, a message counts as delivered as soon as it's sent and is lost if the consumer fails; a quorum queue confirms a message only once a majority of its replicas have it. (RabbitMQ, Acknowledgement modes, Quorum Queues: use cases, Publishers: data safety) - 8
RABBITMQ-1Declare queues whose messages must survive the loss of a node as quorum queues, and makequorumthe default queue type of the virtual host. Classic queues aren't replicated in RabbitMQ 4.x, and a queue's type can't be changed after it's declared. Keep classic queues for temporary, exclusive or low-value data. (RabbitMQ, Quorum Queues: use cases, Classic Queues, Virtual hosts: default queue type) - 8
RABBITMQ-3Make consumers idempotent: the same message can arrive twice, after a redelivery or when a publisher resends a message whose confirm it didn't receive. RabbitMQ recommends idempotent processing over explicit deduplication; theredeliveredflag marks deliveries that a consumer may have seen before. (RabbitMQ, Reliability Guide: consumer side, microservices.io, Idempotent Consumer) - 7
RABBITMQ-4Don't let unroutable messages disappear: publish with themandatoryflag and handle returned messages, or give the exchange an alternate exchange. By default, a message that matches no binding is discarded. (RabbitMQ, Publishers: unroutable message handling, Alternate Exchanges, Reliability Guide: routing)
Consumers and failed messages¶
- 8
RABBITMQ-5Handle poison messages with the quorum queue delivery limit and a dead-letter exchange: keep the limit on (20 by default since RabbitMQ 4.0), and dead-letter messages that exceed it to a queue that someone monitors. Without a dead-letter exchange, such messages are dropped. Where they matter, use at-least-once dead-lettering, because the default strategy can lose them in transit. (RabbitMQ, Quorum Queues: poison message handling, Dead Letter Exchanges, Quorum Queues: at-least-once dead-lettering) - 7
RABBITMQ-6Give every consumer a bounded prefetch, starting between 100 and 300, and tune it by measurement. With unlimited prefetch or automatic acknowledgements, unprocessed deliveries pile up and can exhaust the memory of consumers or nodes. Set prefetch per consumer: quorum queues don't support global QoS. (RabbitMQ, Prefetch and throughput, Consumer Prefetch, Quorum Queues: global QoS) - 6
RABBITMQ-7Retry transient failures with the quorum queue's delayed retry (RabbitMQ 4.3 and later) instead of requeueing at once or building dead-letter cycles with TTLs. Rapid requeue loops overload the queue; delayed retry adds a linear back-off without rewriting the message or risking its loss. (RabbitMQ, Quorum Queues: delayed retry, Dead Letter Exchanges: delayed retries)
Connections and channels¶
- 7
RABBITMQ-8Keep connections long-lived, use separate connections for publishing and consuming, and give each thread its own channel. Opening connections per operation causes high churn that wastes node resources, publishing concurrently on a shared channel is unsafe, and flow control on a publishing connection can hold up the acknowledgements of consumers on the same connection. (RabbitMQ, Connections: high connection churn, Channels, Publishers: concurrency, Production checklist: connection management)
Queue design¶
- 7
RABBITMQ-9Keep queues short: run enough consumers to keep up, cap queue length with a policy, and use a stream instead of a queue for large backlogs, replay or large fan-outs. Queues are optimised for being nearly empty and perform worse with millions of messages; classic queues no longer have a "lazy" mode for large backlogs. (RabbitMQ, Streams: use cases, Queue Length Limit, Quorum Queues: when not to use them, Lazy queues) - 7
RABBITMQ-10Configure dead-lettering, TTLs, length limits and delivery limits through policies, not throughx-arguments hard-coded in applications. Policies can be changed at any time for many queues at once, while hard-coded arguments need application changes and redeployment. The queue type is the exception: set it at declaration or through the default queue type. (RabbitMQ, Dead Letter Exchanges: configuration, Policies)
Security¶
- 9
RABBITMQ-11Delete the defaultguestuser, disable anonymous logins, and give each application its own user with only the permissions it needs. Theguestuser has well-known credentials, and theANONYMOUSmechanism, on by default, lets clients without credentials connect asguest. (RabbitMQ, Production checklist: users, Anonymous login, Access control: default virtual host and user, Authentication mechanisms) - 8
RABBITMQ-12Use TLS for client connections with peer verification, and secure inter-node and CLI traffic too. Where every client can use TLS, turn off the plain listeners. (RabbitMQ, Production checklist: TLS, TLS Support: enabling TLS, peer verification, Production checklist: inter-node authentication)
Operations¶
- 8
RABBITMQ-14Stay on a release series that still has community support, and upgrade along the supported rolling upgrade paths, with all stable feature flags enabled first. Community support for a series ends a few months after the next series ships. (RabbitMQ, Release information, Upgrading: version upgradability) - 7
RABBITMQ-13Monitor with the built-in Prometheus plugin, and alert on queue depth, unacknowledged messages, consumer counts, connection churn and resource alarms. (RabbitMQ, Monitoring with Prometheus-compatible tools, Queue metrics, Connections: high connection churn, Memory and disk alarms)
How to enforce¶
Tools that check the key rules above automatically, in CI, the IDE or a commit hook. "Partly" means the tool covers only some of what the rule asks.
- 6 RabbitMQ Prometheus alerting rules (RabbitMQ Cluster Operator): ready-made Prometheus alerts, as Kubernetes
PrometheusRuleresources, for the metrics of the Prometheus plugin. HighConnectionChurn fires when connections are short-lived, and UnroutableMessages when messages are dropped or returned as unroutable. Partly checksRABBITMQ-4,RABBITMQ-8andRABBITMQ-13. - 5 Operator policies (RabbitMQ docs): limits such as
delivery-limit,max-lengthandoverflowthat operators apply to every matching queue; when an application's policy sets the same key, the more conservative value wins. Partly checksRABBITMQ-5andRABBITMQ-9. - 5
rabbitmq-diagnostics check_certificate_expiration(RabbitMQ CLI): checks the expiry dates of the certificates on every TLS listener of a node, for example in a scheduled job. Partly checksRABBITMQ-12.
Tutorials and further reading¶
- 7 RabbitMQ Tutorials (RabbitMQ): official step-by-step tutorials in many languages, from work queues and routing to reliable publishing with publisher confirms.
- 6 AMQP 0-9-1 Model Explained (RabbitMQ): exchanges, queues, bindings, acknowledgements and the other concepts behind RabbitMQ's main protocol.