RabbitMQ Retry + Dead Letter Queue
Build a safe async pipeline in Go: a retry queue that delays redelivery, a cap on attempts, and a dead-letter queue so one poison message can't block the rest.
Async work is where messages go to get stuck. Here we build a RabbitMQ pipeline in Go that handles failure on purpose: a main queue, a retry queue that delays redelivery with a TTL, a cap on how many times a message is retried, and a dead-letter queue for the ones that never succeed. We declare the topology a piece at a time so the flow of a failing message stays clear — and one poison message can't wedge the whole worker.
What you'll build
- Publish and consume messages with RabbitMQ in Go
- Delay redelivery with a TTL-based retry queue
- Cap retry attempts using the dead-letter count
- Park unprocessable messages in a dead-letter queue
Contents
- An empty Go module
- A local RabbitMQ
- Connect and open a channel
- The main exchange
- The main queue, with an escape hatch
- The retry exchange
- The retry queue that waits, then returns
- The dead-letter queue
- Publish a message
- Consume and ack
- Reject a failure into the retry loop
- Cap the retries, then dead-letter