0.0.3 • Published 3 years ago

nest-microservices-messaging v0.0.3

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
3 years ago

nest-microservices-messaging

How to use

  • install package with npm i -S nest-microservices-messaging
  • Register the MessagingModule to your feature modules:
@Module({})
export class AppModule {
  static register(config: ConfigOptions): DynamicModule {
    return {
      module: AppModule,
      imports: [
        MessagingModule.register(config.messagingOptions),
        ...
      ],
    };
  }
}
  • Once MessagingModule is registered, then you can use PublisherService to publish to RabbitMQ
export class ExampleController {
  constructor (private service: PublisherService) {
    super (service, logger);
  }

  await publish () {
    this.publisherService.publish('my-queue', { hello: 'world' });
  }
}

Messaging options

PropertyTypeRequiredDescription
exchangesMessageQueueOptionstrueContains { name: string, type: string } which defined the exchange name and type of exchange
uriStringtrueUri or your RabbitMQ server
connectionInitOptionsMessageConnectionOptionstrueContains { wait: boolean } for connection resiliency. See https://www.npmjs.com/package/@golevelup/nestjs-rabbitmq for more details