RabbitMQ decouples services with AMQP

RabbitMQ lets services process work asynchronously. An order example shows how publisher confirms, consumer acknowledgements, and quorum queues work together and how applications handle duplicate deliveries.

An online shop receives an order. The order API saves it in a database and responds to the customer. A worker creates the invoice later. If the billing service goes down temporarily, jobs stay in the queue and can be processed after the service restarts.

The interesting case is when the worker has already saved the invoice and its connection to RabbitMQ drops just then. RabbitMQ has yet to receive the acknowledgement and can deliver the same message again. How does the team ensure that this produces a single invoice? RabbitMQ Reliability Guide

How a message gets from the publisher to the worker

In this example, the publisher uses AMQP 0-9-1 to send a message with the routing key order.created to the orders topic exchange. A binding routes it to the billing.invoice queue. If a shipping service later needs the same event, it can have its own queue with a matching binding. Multiple billing workers can share work from the same queue. RabbitMQ at ayedo

The first failure point is before the broker. If the API saves the order and then publishes the event, it can crash between the two steps. The order exists, but the billing job is missing. A transactional outbox solves this at the application level. The API writes the order and the pending event in the same database transaction. A separate publisher reads the outbox and marks the entry as sent once publishing succeeds.

A publisher confirm covers the step as far as the broker

Publisher confirms tell the publisher whether RabbitMQ has handled the message. For a message routed to a quorum queue, a positive confirm follows once a majority of the queue’s replicas have accepted it. The billing worker acknowledges its own processing separately. RabbitMQ documentation on publisher confirms and consumer acknowledgements

A missing binding is easy to overlook. RabbitMQ can send a positive confirm even when a message reaches no queue. If the client publishes with mandatory, it receives basic.return first and the confirm afterward. The outbox publisher must therefore handle both returns and confirms before marking the entry as sent. If the connection drops before the confirm, the outcome is unknown. When publishing again, reuse the event ID so the consumer can recognize a possible duplicate delivery. RabbitMQ documentation on confirms and routing

The worker acknowledges after saving the invoice

The worker sends its consumer acknowledgement once it has saved the invoice durably. If it crashes after the database commit and before the ack, RabbitMQ can redeliver the job. In this example, a unique database key for the order prevents a second invoice record. On redelivery, the worker can recognize the existing invoice and acknowledge the message. Calls to an external service also need a way to handle duplicate execution, such as an idempotency key supported by the service. RabbitMQ Reliability Guide

Prefetch sets how many deliveries a consumer can hold unacknowledged at once. Raising it can support more parallel work. With slow jobs, some workers may hold many deliveries while others have spare capacity. To tune prefetch, look at messages ready for delivery, unacknowledged deliveries, and measured processing time. RabbitMQ monitoring

Set a limit on retries

A brief outage of the billing database can justify a delayed retry. A message without an order ID will still fail on the fifth attempt. Immediate requeueing can repeatedly deliver the same job and tie up worker capacity. The billing service can use a bounded number of delayed retries and send permanently failed messages to an error queue for investigation.

If failed messages need to be retained, test delivery to the error queue as well. By default, RabbitMQ republishes dead letters internally without publisher confirms. Quorum queues support a configurable at-least-once strategy for this transfer. Test with the target queue unavailable to see whether the selected strategy meets your needs. Dead Letter Exchanges · Quorum Queues

Test quorum queues under realistic failures

A quorum queue with three replicas needs two available members. If the leader fails, the remaining majority can elect a new one. Check which RabbitMQ nodes actually host the queue members and which failures could affect those nodes together. The ayedo documentation for the Polycrate rabbitmq-operator block shows how to set up the operator and RabbitMQ cluster separately and configure cluster replicas. Verify membership of the specific queue during acceptance testing. RabbitMQ operator in the ayedo Polycrate Hub · Quorum Queues

Failure What the test should show
The binding to the billing queue is missing. The publisher handles basic.return and leaves the outbox entry unsent.
The connection drops before the confirm. The publisher retries with the same event ID. The job produces at most one invoice.
The worker crashes after saving. The job is redelivered. The existing invoice stays in place.
The leader of a three-replica queue fails. The remaining majority elects a new leader. Clients resume work after the interruption.
The error queue is temporarily unavailable. The configured dead-letter strategy behaves as intended. The operations team can detect the issue.

Managed RabbitMQ at ayedo

ayedo operates RabbitMQ on Kubernetes in Germany and handles operations, monitoring, and backups. The application team designs the exchanges and bindings and decides how messages are processed. Use expected load and availability requirements to decide which queues benefit from replication and which failures the message flow needs to tolerate. Managed RabbitMQ at ayedo

Planning to use RabbitMQ for a specific message flow? Talk to us about your queue topology, load, and availability requirements.