#Integration with RabbitMQ

4 messages · Page 1 of 1 (latest)

azure bolt
#

This is my main.ts:

import { NestFactory } from '@nestjs/core';
import { RmqOptions, Transport } from '@nestjs/microservices';
import { SummaryModule } from './summary/summary.module';
import { Logger } from 'nestjs-pino';

async function bootstrap() {
  const app = await NestFactory.createMicroservice<RmqOptions>(SummaryModule, {
    transport: Transport.RMQ,
    options: {
      urls: [process.env.RMQ_URL],
      queue: 'summarizer',
      queueOptions: {
        durable: false,
      },
    },
  });

  app.useLogger(app.get(Logger));
  await app.listen();
}

bootstrap();

Ok, with this, now I can receive messagens in my controller, but how can I publish messages?

This is my module:

import { Module } from '@nestjs/common';
import { SummaryController } from './summary.controller';
import { SummaryService } from './summary.service';
import { S3Service } from 'src/infra/storage/s3.service';
import { ClientsModule, Transport } from '@nestjs/microservices';
import { LoggerModule } from 'nestjs-pino';

@Module({
  imports: [
    LoggerModule.forRoot(),
    ClientsModule.register([
      {
        name: 'RMQ_SUMMARIZER',
        transport: Transport.RMQ,
        options: {
          urls: [process.env.RMQ_URL],
          queue: 'summarizer',
          queueOptions: {
            durable: false,
          },
        },
      },
    ]),
  ],
  controllers: [SummaryController],
  providers: [SummaryService, S3Service],
})
export class SummaryModule {}

Is necessary reconfig RMQ again here? Can I use the config that was used to boot the app?

cosmic lichen
#

The ClientsModule is for sending messages using the configured client. It's not necessary in the actuasl receiver server

azure bolt
cosmic lichen