golevelup / nestjs

A collection of badass modules and utilities to help you level up your NestJS applications 🚀

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NestJs-rabbitmq Connection loss without reason && No reconnect

guidiamond opened this issue · comments

After some time running my application for some reason I keep getting a connection loss.

This is the error it shows:

[Nest] 369295 - 06/02/2024, 10:13:51 PM ERROR [AmqpConnection] Disconnected from RabbitMQ broker (default) Error: Unexpected close at succeed (/home/guidiamond/Work/juri-api/node_modules/amqplib/lib/connection.js:229:15) at onOpenOk (/home/guidiamond/Work/juri-api/node_modules/amqplib/lib/connection.js:211:7) at /home/guidiamond/Work/juri-api/node_modules/amqplib/lib/connection.js:114:11 at /home/guidiamond/Work/juri-api/node_modules/amqplib/lib/connection.js:107:11 at Socket.recv (/home/guidiamond/Work/juri-api/node_modules/amqplib/lib/connection.js:456:9) at Object.onceWrapper (node:events:633:28) at Socket.emit (node:events:519:28) at Socket.emit (node:domain:488:12) at emitReadable_ (node:internal/streams/readable:832:12) at processTicksAndRejections (node:internal/process/task_queues:81:21)

Right after that I get:
/home/guidiamond/Work/juri-api/node_modules/amqplib/lib/channel.js:369 throw new IllegalOperationError(msg, stack); ^ IllegalOperationError: Channel closed at ConfirmChannel.<anonymous> (/home/guidiamond/Work/juri-api/node_modules/amqplib/lib/channel.js:369:11) at ConfirmChannel.nack (/home/guidiamond/Work/juri-api/node_modules/amqplib/lib/channel_model.js:221:10) at requeueErrorHandler (/home/guidiamond/Work/juri-api/node_modules/@golevelup/nestjs-rabbitmq/src/amqp/errorBehaviors.ts:27:11) at /home/guidiamond/Work/juri-api/node_modules/@golevelup/nestjs-rabbitmq/src/amqp/connection.ts:507:19 at processTicksAndRejections (node:internal/process/task_queues:95:5)

The thing is I'm running this locally and the only connection that gets lost is with rabbitmq, and for some reason it doesn't try to reconnect after that. Does anybody know what could be the issue here?

This is what I added to imports in my API's module:

   RabbitMQModule.forRoot(RabbitMQModule, {
      exchanges: [
        {
          name: Exchanges.API,
          type: 'direct',
          options: {
            durable: true,
          },
        },
        {
          name: Exchanges.DEAD_LETTER,
          type: 'direct',
          options: {
            durable: true,
          },
        },
      ],
      channels: {
        [Channels.MAPEIA_V1]: {
          prefetchCount: 15,
          default: true,
        },
        [Channels.RESTORE_V2]: {
          prefetchCount: 2,
          default: false,
        },
      },
      queues: [
        {
          name: Queues.PROCESSA_V1_DLQ,
          routingKey: Queues.PROCESSA_V1_DLQ,
          exchange: Exchanges.DEAD_LETTER,
          createQueueIfNotExists: true,
        },
        {
          name: Queues.RESTORE_V2_DLQ,
          routingKey: Queues.RESTORE_V2_DLQ,
          exchange: Exchanges.DEAD_LETTER,
          createQueueIfNotExists: true,
        },
      ],
      uri: `amqp://${config.getTyped('rabbitMq.username')}:${config.getTyped(
        'rabbitMq.password',
      )}@${config.getTyped('rabbitMq.hostname')}:${config.getTyped(
        'rabbitMq.port',
      )}`,
      enableControllerDiscovery: true,
    }),