我已经使用@nestjs plus/rabbitmq库创建了一个发布/订阅模型,但无法从订阅者向发布者发送确认

我已经使用@nestjs plus/rabbitmq库创建了一个发布/订阅模型,但无法从订阅者向发布者发送确认,rabbitmq,nestjs,Rabbitmq,Nestjs,我使用了@RabbitSubscribe()decorator进行订阅,publisher和Pub/Sub的AmqpConnection.publish()工作正常。但我希望在消息传递时,订阅者向发布者回复确认 我希望发布者应该收到订阅者的确认。要获得答案,您需要使用RPC处理程序 发送消息: const requestOptions: RequestOptions = { payload: {foo: 'bar'}, exchange: 'exchange1', rou

我使用了
@RabbitSubscribe()
decorator进行订阅,publisher和Pub/Sub的
AmqpConnection.publish()
工作正常。但我希望在消息传递时,订阅者向发布者回复确认


我希望发布者应该收到订阅者的确认。

要获得答案,您需要使用RPC处理程序

发送消息:

const requestOptions: RequestOptions = {
    payload: {foo: 'bar'},
    exchange: 'exchange1',
    routingKey: 'rpc-route'
};
const result = await this.amqpConnection.request(requestOptions);
消息处理和响应:

@RabbitRPC({
    exchange: 'exchange1',
    routingKey: 'rpc-route',
    queue: 'rpc-queue'
})
public async rpcHandler(msg: {}) {
    return {
        response: 42
    };
}