Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

nestjs - NEst RabbitMQ RPC nack doesn't reject the promise

With nestJS rabbit MQ I use RPC from one server to another one. What I basically want is await this.amqpConnection.request to reject the promise when the consumer throw an error. As I understand from this and this and this documentation when you NACK (negative ack) the message it should put the RPC response to a corresponding queue with an error information which would be passed to a client. Here's some code example:

Producer

import { AmqpConnection } from '@golevelup/nestjs-rabbitmq';

let amqpConnection: AmqpConnection;

sendMessage(payload: any) {
  try {
      const result = await this.amqpConnection.request({
        exchange: 'user',
        routingKey: 'test',
        queue: 'test',
        payload,
      });
      console.log(result);
  } catch (e) {
      console.error(e); // I expect this flow !!! 
  }
}
    

Consumer:

  @RabbitRPC({
    exchange: 'user',
    routingKey: 'test',
    queue: 'test',
    errorBehavior: MessageHandlerErrorBehavior.NACK
  })
  public async rpcHandler(payload: any): Promise<any> {
     throw Error("Error text that should be proxied to console.error"):
  }
  

But the message doesn't even return to the client. Client gets rejected after a timeout, rather because of an error during consumer processing. If my understanding is not correct I would like to know if there's a builtin mechanism with nestjs to reject the message w/o manually creating some response types for an error and handling it on a client.

question from:https://stackoverflow.com/questions/65643952/nest-rabbitmq-rpc-nack-doesnt-reject-the-promise

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...