move messaging to its own module
This commit is contained in:
parent
0825a5f0d9
commit
fac5ae8f26
|
@ -1,49 +1,24 @@
|
|||
import { Module } from '@nestjs/common';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { AuthenticationModule } from '@modules/authentication/authentication.module';
|
||||
import { EventEmitterModule } from '@nestjs/event-emitter';
|
||||
import {
|
||||
MessageBrokerModule,
|
||||
MessageBrokerModuleOptions,
|
||||
} from '@mobicoop/message-broker-module';
|
||||
import { HealthModule, HealthModuleOptions } from '@mobicoop/health-module';
|
||||
import { AuthorizationModule } from '@modules/authorization/authorization.module';
|
||||
import {
|
||||
AUTHENTICATION_REPOSITORY,
|
||||
USERNAME_REPOSITORY,
|
||||
} from '@modules/authentication/authentication.di-tokens';
|
||||
import { MESSAGE_PUBLISHER } from './modules/message-publisher/message-publisher.di-tokens';
|
||||
import { MESSAGE_PUBLISHER } from './modules/messager/messager.di-tokens';
|
||||
import { MessagePublisherPort } from '@mobicoop/ddd-library';
|
||||
import { ICheckRepository } from '@mobicoop/health-module/dist/core/domain/types/health.types';
|
||||
import { MessagePublisherModule } from './modules/message-publisher/message-publisher.module';
|
||||
import { MessagerModule } from './modules/messager/messager.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot({ isGlobal: true }),
|
||||
EventEmitterModule.forRoot(),
|
||||
MessageBrokerModule.forRootAsync({
|
||||
imports: [ConfigModule],
|
||||
inject: [ConfigService],
|
||||
useFactory: async (
|
||||
configService: ConfigService,
|
||||
): Promise<MessageBrokerModuleOptions> => ({
|
||||
uri: configService.get<string>('MESSAGE_BROKER_URI'),
|
||||
exchange: configService.get<string>('MESSAGE_BROKER_EXCHANGE'),
|
||||
name: 'auth',
|
||||
handlers: {
|
||||
userUpdated: {
|
||||
routingKey: 'user.updated',
|
||||
queue: 'auth-user-updated',
|
||||
},
|
||||
userDeleted: {
|
||||
routingKey: 'user.deleted',
|
||||
queue: 'auth-user-deleted',
|
||||
},
|
||||
},
|
||||
}),
|
||||
}),
|
||||
HealthModule.forRootAsync({
|
||||
imports: [AuthenticationModule, MessagePublisherModule],
|
||||
imports: [AuthenticationModule, MessagerModule],
|
||||
inject: [
|
||||
AUTHENTICATION_REPOSITORY,
|
||||
USERNAME_REPOSITORY,
|
||||
|
@ -62,9 +37,9 @@ import { MessagePublisherModule } from './modules/message-publisher/message-publ
|
|||
}),
|
||||
AuthenticationModule,
|
||||
AuthorizationModule,
|
||||
MessagePublisherModule,
|
||||
MessagerModule,
|
||||
],
|
||||
controllers: [],
|
||||
exports: [AuthenticationModule, MessagePublisherModule],
|
||||
exports: [AuthenticationModule, MessagerModule],
|
||||
})
|
||||
export class AppModule {}
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
import { Module, Provider } from '@nestjs/common';
|
||||
import { MESSAGE_PUBLISHER } from './message-publisher.di-tokens';
|
||||
import { MessageBrokerPublisher } from '@mobicoop/message-broker-module';
|
||||
|
||||
const messagePublishers: Provider[] = [
|
||||
{
|
||||
provide: MESSAGE_PUBLISHER,
|
||||
useClass: MessageBrokerPublisher,
|
||||
},
|
||||
];
|
||||
|
||||
@Module({
|
||||
providers: [...messagePublishers],
|
||||
exports: [MESSAGE_PUBLISHER],
|
||||
})
|
||||
export class MessagePublisherModule {}
|
|
@ -0,0 +1,46 @@
|
|||
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';
|
||||
|
||||
const imports = [
|
||||
MessageBrokerModule.forRootAsync({
|
||||
imports: [ConfigModule],
|
||||
inject: [ConfigService],
|
||||
useFactory: async (
|
||||
configService: ConfigService,
|
||||
): Promise<MessageBrokerModuleOptions> => ({
|
||||
uri: configService.get<string>('MESSAGE_BROKER_URI'),
|
||||
exchange: configService.get<string>('MESSAGE_BROKER_EXCHANGE'),
|
||||
name: 'auth',
|
||||
handlers: {
|
||||
userUpdated: {
|
||||
routingKey: 'user.updated',
|
||||
queue: 'auth-user-updated',
|
||||
},
|
||||
userDeleted: {
|
||||
routingKey: 'user.deleted',
|
||||
queue: 'auth-user-deleted',
|
||||
},
|
||||
},
|
||||
}),
|
||||
}),
|
||||
];
|
||||
|
||||
const providers: Provider[] = [
|
||||
{
|
||||
provide: MESSAGE_PUBLISHER,
|
||||
useClass: MessageBrokerPublisher,
|
||||
},
|
||||
];
|
||||
|
||||
@Module({
|
||||
imports,
|
||||
providers,
|
||||
exports: [MESSAGE_PUBLISHER],
|
||||
})
|
||||
export class MessagerModule {}
|
Loading…
Reference in New Issue