1.1.9 • Published 1 year ago

ecom-rabbitmq v1.1.9

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year 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

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago