Message Reliability in RabbitMQ 4.x: Confirms, Retries, Dead Lettering, and Idempotency
Baseline: RabbitMQ 4.x or a currently supported 3.13+ release, with a Java client version compatible with the server. Do not use latest or the default password.
1. Production Path
Publisher -> Exchange -> Queue -> Consumer
| |
publisher confirm ack/retry/dead letter
Publisher confirms determine whether the broker has received a message, while consumer acknowledgments determine whether it was processed successfully. The two are not interchangeable.
2. Publisher-Side Reliability
Enable publisher confirms, and consider a publish successful only after the broker confirms it. The application must still handle nacks, dropped connections, and timeouts, and use a business message ID for idempotency.
Durable messages, durable exchanges and queues, and publisher confirms all reduce the risk of loss, but they do not mean the business operation has succeeded. For critical events, use a local message table or the Outbox pattern so that the database state and the pending message are committed in the same transaction.
3. Consumer-Side Processing
Acknowledge a message only after the business operation succeeds. Transient failures can be retried a limited number of times, while messages that cannot be processed go to a dead-letter queue. Retries must have a maximum attempt count and a backoff limit; otherwise, infinite requeueing creates a hot loop.
Consumer logic must be idempotent. Network retries, consumer restarts, and lost acknowledgments can all cause the same message to be delivered again.
4. High Availability and Delayed Messages
For high-availability deployments, start by evaluating quorum queues. The behavior of classic queues, mirroring policies, and delayed-message plugins depends on the RabbitMQ version, so deployment commands from the 3.8 era cannot be reused as-is.
For delayed messages, consider TTL + DLX, a plugin, Streams, or an application-level scheduler. Before choosing an approach, confirm its ordering, retry behavior, capacity, and operational cost.
5. Security and Monitoring
Create a least-privilege user for each application, and enable TLS and access controls for the management interface. Monitor publisher confirms, nacks, unacknowledged messages, queue depth, consumption latency, retry counts, and dead-letter volume. Set prefetch so that a single consumer does not hold too many unacknowledged messages at once.