Last week I found myself struggling to find some documentation about dead letter exchanges with Nest.js & RabbitMQ. Some GitHub issues recommend external packages, but you can actually do it with plain Nest.js!
We’ll require some basic knowledge of both RabbitMQ and Nest.js.
The complete source code is available here. If you wanna skip to it right ahead.
Photo by Joanna Kosinska on Unsplash
RabbitMQ dead letters messages to which at least one of the following points apply:
requeue: false
.The dead lettered messages are then forwarded to a dead letter exchange if one was specified. In our example, we’ll simply forward them to another RabbitMQ queue and process them there. This pattern is great to implement error-resilient workers!
Glad that you ask! We’ll build two microservices that will simulate the preparation of a burger. Sadly our chef drops every third burger patty. We’ll introduce some error handling to cover that.
Sequence Diagram of our Burger Ordering
As we can see we have 4 components involved in the making of a burger:
Burger Queue
and processes them.Recovery Queue
and redirects them to the Burger Queue
. Also increases retry count by 1. Emits failure if retry count exceeds 4.#javascript #programming #nestjs #typescript #node