Rabbitmq component for NestJs.
Yarn
yarn add nestjs-rabbitmq
NPM
npm install nestjs-rabbitmq --save
Let's import the RabbitMqModule in app.module.ts
import { Module } from '@nestjs/common';
import { RabbitMqModule} from 'nestjs-rabbitmq'
@Module({
imports: [
RabbitMqModule.forRoot(options)
],
})
export class AppModule {}
With Async
import { Module } from '@nestjs/common';
import { RabbitMqModule} from 'nestjs-rabbitmq'
@Module({
imports: [
RabbitMqModule.forRootAsync({
useFactory: (configService: ConfigService) => configService.get('rabbitmq'), // or use async method
//useFactory: async (configService: ConfigService) => configService.get('rabbitmq'),
inject:[ConfigService]
}),
],
})
export class AppModule {}
Options
interface RabbitMqModuleOptions {
user?: string, //Default guest
passwd?: string, //Default guest
host?: string, //Default localhost
port?: number //Default 5672
}
That's it!