1.1.9 • Published 10 months ago

ecom-rabbitmq v1.1.9

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

NestJS RabbitMQ Module

A comprehensive RabbitMQ module for NestJS applications, providing easy integration with RabbitMQ for microservices communication.

Installation

npm install ecom-rabbitmq

Configuration

Before using the module, make sure to set the RABBITMQ_URL environment variable with your RabbitMQ server URLs. You can set this in your .env file:

RABBITMQ_URL=amqp://localhost:5672

Usage

Importing the Module

To use the RabbitMQ module in your NestJS application, import it in your app module:

import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { RabbitMQModule } from 'ecom-rabbitmq';
import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
  imports: [
    ConfigModule.forRoot(),
    RabbitMqClientModule.registerQueues({
      imports: [ConfigModule],
      queues: ['ABC_QUEUE', 'EFG_QUEUE', 'HIJ_QUEUE'],
    }),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class MyModule {}

Initialize the QUEUE to listen to

main.ts

const rmqConfigs = RabbitMqClientModule.initRmq(
  configService,
  PC_MS_QUEUES.name,
);

app.connectMicroservice<RmqOptions>(rmqConfigs);

await app.startAllMicroservices();

API Reference

RabbitMQModule

  • forRootAsync(options: IRabbitMQModuleAsyncOptions): DynamicModule

    Creates a global asynchronous RabbitMQ module.

MyService

@Injectable()
export class MyService {
  constructor(@Inject('ABC_QUEUE') private readonly txnClient: ClientProxy) {}

  sendMessage() {
    this.txnClient.emit('PATTERN_QUEUE', {
      message: 'Hello World!',
    });
  }
}
1.1.9

10 months ago

1.1.8

11 months ago

1.1.7

11 months ago

1.1.6

11 months ago

1.1.5

11 months ago

1.1.4

11 months ago

1.1.3

11 months ago

1.1.2

12 months ago

1.1.1

12 months ago

1.1.0

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago

0.0.7

12 months ago

0.0.6

12 months ago

0.0.5

12 months ago

0.0.4

12 months ago

0.0.3

12 months ago

0.0.2

12 months ago

0.0.1

12 months ago