54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
import { Module, Provider } from '@nestjs/common';
|
|
import { MESSAGE_PUBLISHER } from './messager.di-tokens';
|
|
import {
|
|
MessageBrokerModule,
|
|
MessageBrokerModuleOptions,
|
|
MessageBrokerPublisher,
|
|
} from '@mobicoop/message-broker-module';
|
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
import {
|
|
AD_CREATED_MESSAGE_HANDLER,
|
|
AD_CREATED_QUEUE,
|
|
AD_CREATED_ROUTING_KEY,
|
|
SERVICE_NAME,
|
|
} from '@src/app.constants';
|
|
|
|
const imports = [
|
|
MessageBrokerModule.forRootAsync({
|
|
imports: [ConfigModule],
|
|
inject: [ConfigService],
|
|
useFactory: async (
|
|
configService: ConfigService,
|
|
): Promise<MessageBrokerModuleOptions> => ({
|
|
uri: configService.get<string>('MESSAGE_BROKER_URI') as string,
|
|
exchange: {
|
|
name: configService.get<string>('MESSAGE_BROKER_EXCHANGE') as string,
|
|
durable: configService.get<boolean>(
|
|
'MESSAGE_BROKER_EXCHANGE_DURABILITY',
|
|
) as boolean,
|
|
},
|
|
name: SERVICE_NAME,
|
|
handlers: {
|
|
[AD_CREATED_MESSAGE_HANDLER]: {
|
|
routingKey: AD_CREATED_ROUTING_KEY,
|
|
queue: AD_CREATED_QUEUE,
|
|
},
|
|
},
|
|
}),
|
|
}),
|
|
];
|
|
|
|
const providers: Provider[] = [
|
|
{
|
|
provide: MESSAGE_PUBLISHER,
|
|
useClass: MessageBrokerPublisher,
|
|
},
|
|
];
|
|
|
|
@Module({
|
|
imports,
|
|
providers,
|
|
exports: [MESSAGE_PUBLISHER],
|
|
})
|
|
export class MessagerModule {}
|