import { DynamicModule , Module } from '@nestjs/common' ; import { ClientProxyFactory , Transport } from '@nestjs/microservices' ; import { ConfigService } from '@fc/config' ; import { RabbitmqConfig } from './dto' ; @ Module ( { } ) export class RabbitmqModule { param moduleName returns module static RABBIT_CLASS_SUFFIX = 'Broker' ; static registerFor ( moduleName ) { const clientName = `${ moduleName }${ RabbitmqModule . RABBIT_CLASS_SUFFIX }` ; const BrokerProvider = { provide : clientName , useFactory : ( config ) => { const options = config . get < RabbitmqConfig > ( clientName ) ; return ClientProxyFactory . create ( { transport : Transport . RMQ , options , } ) ; } , inject : [ ConfigService ] , } ; return { module : RabbitmqModule , providers : [ BrokerProvider ] , exports : [ BrokerProvider ] , } ; } }