NestJS microservices error with "No matching message handler"

Published

I’m building an application with microservices communicating through RabbitMQ (request-response pattern).
Everything works fine but still I have a problem with error "There is no matching message handler defined in the remote service."
When I send POST to my Client app, it should simply send the message with data through client (ClientProxy) and the Consumer app should response. This functionality actually works, but always only for the second time. I know it sounds strange but on my first POST request there is always the error from Client and my every second POST request works. However this problem is everywhere in my whole application, so the particular POST request is just for the example.

Here is the code:

Client:

@Post('devices')
async pushDevices(
    @Body(new ParseArrayPipe({ items: DeviceDto }))
    devices: DeviceDto[]
    ) {
    this.logger.log('Devices received'); 
    return this.client.send(NEW_DEVICES_RECEIVED, devices)
}

Consumer:

 @MessagePattern(NEW_DEVICES_RECEIVED)
 async pushDevices(@Payload() devices: any, @Ctx() context: RmqContext) {
    console.log('RECEIVED DEVICES');
    console.log(devices);
    const channel = context.getChannelRef();
    const originalMsg = context.getMessage();
    channel.ack(originalMsg);
    return 'ANSWER';
  }

Client has the RMQ settings with queueOptions: {durable: true} and the consumer as well queueOptions: {durable: true} with noAck: false

Please do you have any ideas what may causes the problem? I have tried sending the data with JSON.stringify and changing the message structure to {data: devices} but the error is still there.

Source: Docker Questions

Published
Categorised as docker, microservices, nestjs, rabbitmq Tagged , , ,

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq