RabbitMQ in NestJS, error on both Producer and Consumer

Viewed 2724

I have the following app https://github.com/rengthp/nestjs-rabbitmq-microservice

But I get on Producer :

[Nest] 6156 - 04/03/2021, 13:28:53 [ClientProxy] Disconnected from RMQ. Trying to reconnect. +25469ms [Nest] 6156 - 04/03/2021, 13:28:53 [ClientProxy] Object:

{
  "err": {
    "code": 406,
    "classId": 50,
    "methodId": 10
  }
}
 +3ms

and on Consumer:

111ms
[Nest] 1180   - 04/03/2021, 13:22:31   [Server] Disconnected from RMQ. Trying to reconnect. +1058ms
[Nest] 1180   - 04/03/2021, 13:22:37   [Server] Disconnected from RMQ. Trying to reconnect. +6006ms
[Nest] 1180   - 04/03/2021, 13:22:43   [Server] Disconnected from RMQ. Trying to reconnect. +6017ms
[Nest] 1180   - 04/03/2021, 13:22:49   [Server] Disconnected from RMQ. Trying to reconnect. +6026ms

What could be wrong? the server is working...

3 Answers

This error came up because you re-declare an existing queue with different parameters. The solution is simple. The option queue for both producers and consumers must be the same and all option parameters must be the same.

try to left time to api gateway to connect rabbit,

in your controller, use onApplicationBootstrap function

async onApplicationBootstrap() { await this._clientProxyUser.connect();}

you can read more here lifecycle events nestjs

For me changing the type of the RabbitMQ QUEUE I was using from transient to durable fixed it

Related