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

Categories

0 votes
1.7k 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 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...