AlariCode / nestjs-rmq

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

How to handle ERROR_NO_ROUTE? #49

Closed Vrainy closed 2 years ago

Vrainy commented 2 years ago

Hi. Thank you for this great library.

How can i handle ERROR_NO_ROUTE, and confirm the message?

Background

The queue gets a message with 'test'(topic), but it's route has been removed. The consumer received this message , reply an error , but no ack. The state of the message will remain unack.

Related Code

const route = this.getRouteByTopic(msg.fields.routingKey);
if (route) {
    msg = await this.useMiddleware(msg);
    requestEmitter.emit(route, msg);
} else {
    this.reply('', msg, new RMQError(ERROR_NO_ROUTE, ERROR_TYPE.TRANSPORT));
}

expectation

I know the more correct way is to remove the useless bindings, but it's would be nice that could handle such error in project code.

AlariCode commented 2 years ago

@Vrainy thanks! Added nack in version 2.6.1 for ERROR_NO_ROUTE.