This repository contains a set of examples as well as the facade over Bunny to help with reliable message delivery.
Assumptions:
- Both producer and consumer of messages are synchronous. Php is still not a good fit for the async workload.
- You have rabbitmq cluster of 3+ nodes with
pause-minoritypolicy - You rely on competing consumers, and you don't care about the order in which messages are going to be processed
- Queue/Exchange bindings are static. i.e., there are no dynamic routing rules applied so we could avoid problems that there is no consumer for a given routing key
- Your application is running in Kubernetes
What we need:
- Reconnect and retry with back-off when a node is not available
- Ability to manually send heartbeat frame in case of a long-running task to keep the connection alive
- Store outbound messages in the buffer until the broker confirms delivery
- Retry publishing if broker rejected a message
Examples rely on toxiproxy. I was also lazy to provide PHP image. To simplify infrastructure, only RabbitMQ runs in docker and network conditions simulated by toxiproxy, which should be installed on your machine.
- Jack Vanlightly's blog contains a lot of information on reliability in messaging systems