refactor configuration using dddlibrary

This commit is contained in:
sbriat
2023-10-19 17:16:05 +02:00
parent d9cf800cf8
commit 367307b02e
106 changed files with 4934 additions and 11828 deletions

View File

@@ -0,0 +1 @@
export const MESSAGE_PUBLISHER = Symbol('MESSAGE_PUBLISHER');

View File

@@ -0,0 +1,43 @@
import { Module, Provider } from '@nestjs/common';
import { MESSAGE_PUBLISHER } from './messager.di-tokens';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { SERVICE_NAME } from '@src/app.constants';
import {
MessageBrokerModule,
MessageBrokerModuleOptions,
MessageBrokerPublisher,
} from '@mobicoop/message-broker-module';
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,
}),
}),
];
const providers: Provider[] = [
{
provide: MESSAGE_PUBLISHER,
useClass: MessageBrokerPublisher,
},
];
@Module({
imports,
providers,
exports: [MESSAGE_PUBLISHER],
})
export class MessagerModule {}