AlariCode / nestjs-rmq

A custom library for NestJS microservice. It allows you to use RabbitMQ or AMQP.
https://purpleschool.ru
MIT License
285 stars 38 forks source link

Putting errors into a queue #16

Closed Saro-DA closed 3 years ago

Saro-DA commented 3 years ago

Hello.

Thank you very much for this great module.

There is a scenario where I want to avoid reply-to RPC and want to put errors along with the original data into a specific error queue to be processed later.

How is this possible?

AlariCode commented 3 years ago

@Saro-DA, hello and thanks for using library! If I understand your question correctly, you need:

  1. Service A sends message to service B
  2. If Service B have an error, it sends data to queue “errorQueue”.

If so, my recommendations:

  1. A sends to B
  2. When B processed message and got error inside method it sends error and data to another queue: this.rmqService.notify(“errorQueue”, { originalData, occurredError });
  3. And then throw this error to reply to A service.
  4. And I recommend adding service C to errorQueue to process and collect errors, because RMQ is not a good storage.
Saro-DA commented 3 years ago

Thank you for your quick reply @AlariCode. Yes, that's the intention. However, I want to use the global error handler to catch errors especially, validation errors. In the error handler, I noticed that the original data is not visible. Also, the client to send the error to a queue is not accessible in the error handler, neither it is in the interceptors and middlewares. Is there a workaround for this?

AlariCode commented 3 years ago

I think there is no way to get original message into error handler right now.