Merge branch 'moveMessager' into 'main'

Move messager

See merge request v3/service/auth!44
This commit is contained in:
Sylvain Briat 2023-07-18 07:11:07 +00:00
commit 51c33010c8
6 changed files with 55 additions and 50 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "@mobicoop/auth", "name": "@mobicoop/auth",
"version": "0.2.0", "version": "0.3.0",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@mobicoop/auth", "name": "@mobicoop/auth",
"version": "0.2.0", "version": "0.3.0",
"license": "AGPL", "license": "AGPL",
"dependencies": { "dependencies": {
"@automapper/classes": "^8.7.7", "@automapper/classes": "^8.7.7",

View File

@ -1,6 +1,6 @@
{ {
"name": "@mobicoop/auth", "name": "@mobicoop/auth",
"version": "0.2.0", "version": "0.3.0",
"description": "Mobicoop V3 Auth Service", "description": "Mobicoop V3 Auth Service",
"author": "sbriat", "author": "sbriat",
"private": true, "private": true,

View File

@ -1,49 +1,24 @@
import { Module } from '@nestjs/common'; import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config'; import { ConfigModule } from '@nestjs/config';
import { AuthenticationModule } from '@modules/authentication/authentication.module'; import { AuthenticationModule } from '@modules/authentication/authentication.module';
import { EventEmitterModule } from '@nestjs/event-emitter'; import { EventEmitterModule } from '@nestjs/event-emitter';
import {
MessageBrokerModule,
MessageBrokerModuleOptions,
} from '@mobicoop/message-broker-module';
import { HealthModule, HealthModuleOptions } from '@mobicoop/health-module'; import { HealthModule, HealthModuleOptions } from '@mobicoop/health-module';
import { AuthorizationModule } from '@modules/authorization/authorization.module'; import { AuthorizationModule } from '@modules/authorization/authorization.module';
import { import {
AUTHENTICATION_REPOSITORY, AUTHENTICATION_REPOSITORY,
USERNAME_REPOSITORY, USERNAME_REPOSITORY,
} from '@modules/authentication/authentication.di-tokens'; } 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 { MessagePublisherPort } from '@mobicoop/ddd-library';
import { ICheckRepository } from '@mobicoop/health-module/dist/core/domain/types/health.types'; 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({ @Module({
imports: [ imports: [
ConfigModule.forRoot({ isGlobal: true }), ConfigModule.forRoot({ isGlobal: true }),
EventEmitterModule.forRoot(), 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({ HealthModule.forRootAsync({
imports: [AuthenticationModule, MessagePublisherModule], imports: [AuthenticationModule, MessagerModule],
inject: [ inject: [
AUTHENTICATION_REPOSITORY, AUTHENTICATION_REPOSITORY,
USERNAME_REPOSITORY, USERNAME_REPOSITORY,
@ -62,9 +37,9 @@ import { MessagePublisherModule } from './modules/message-publisher/message-publ
}), }),
AuthenticationModule, AuthenticationModule,
AuthorizationModule, AuthorizationModule,
MessagePublisherModule, MessagerModule,
], ],
controllers: [], controllers: [],
exports: [AuthenticationModule, MessagePublisherModule], exports: [AuthenticationModule, MessagerModule],
}) })
export class AppModule {} export class AppModule {}

View File

@ -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 {}

View File

@ -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 {}