refactor message broker
This commit is contained in:
parent
a9c180fbb2
commit
e7f0ab0652
|
@ -4,3 +4,4 @@ SERVICE_PORT=5099
|
|||
|
||||
# RABBIT MQ
|
||||
RMQ_URI=amqp://v3-broker:5672
|
||||
RMQ_EXCHANGE=mobicoop
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
import { ConfigService } from '@nestjs/config';
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { AppModule } from './app.module';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
await app.listen(3000);
|
||||
const configService: ConfigService = app.get(ConfigService);
|
||||
await app.listen(configService.get<number>('SERVICE_PORT'));
|
||||
}
|
||||
bootstrap();
|
||||
|
|
|
@ -15,10 +15,132 @@ import { TerritoryController } from './logger/adapters/primaries/territory.contr
|
|||
useFactory: async (configService: ConfigService) => ({
|
||||
exchanges: [
|
||||
{
|
||||
name: 'logging',
|
||||
name: configService.get<string>('RMQ_EXCHANGE'),
|
||||
type: 'topic',
|
||||
},
|
||||
],
|
||||
handlers: {
|
||||
loggingAuthCreateCrit: {
|
||||
exchange: configService.get<string>('RMQ_EXCHANGE'),
|
||||
routingKey: 'logging.auth.create.crit',
|
||||
},
|
||||
loggingAuthDeleteCrit: {
|
||||
exchange: configService.get<string>('RMQ_EXCHANGE'),
|
||||
routingKey: 'logging.auth.delete.crit',
|
||||
},
|
||||
loggingAuthUsernameAddWarning: {
|
||||
exchange: configService.get<string>('RMQ_EXCHANGE'),
|
||||
routingKey: 'logging.auth.username.add.warning',
|
||||
},
|
||||
loggingAuthUsernameDeleteWarning: {
|
||||
exchange: configService.get<string>('RMQ_EXCHANGE'),
|
||||
routingKey: 'logging.auth.username.delete.warning',
|
||||
},
|
||||
loggingAuthPasswordUpdateWarning: {
|
||||
exchange: configService.get<string>('RMQ_EXCHANGE'),
|
||||
routingKey: 'logging.auth.password.update.warning',
|
||||
},
|
||||
loggingAuthUsernameUpdateWarning: {
|
||||
exchange: configService.get<string>('RMQ_EXCHANGE'),
|
||||
routingKey: 'logging.auth.username.update.warning',
|
||||
},
|
||||
loggingConfigurationCreateInfo: {
|
||||
exchange: configService.get<string>('RMQ_EXCHANGE'),
|
||||
routingKey: 'logging.configuration.create.info',
|
||||
},
|
||||
loggingConfigurationCreateWarning: {
|
||||
exchange: configService.get<string>('RMQ_EXCHANGE'),
|
||||
routingKey: 'logging.configuration.create.warning',
|
||||
},
|
||||
loggingConfigurationCreateCrit: {
|
||||
exchange: configService.get<string>('RMQ_EXCHANGE'),
|
||||
routingKey: 'logging.configuration.create.crit',
|
||||
},
|
||||
loggingConfigurationDeleteInfo: {
|
||||
exchange: configService.get<string>('RMQ_EXCHANGE'),
|
||||
routingKey: 'logging.configuration.delete.info',
|
||||
},
|
||||
loggingConfigurationDeleteCrit: {
|
||||
exchange: configService.get<string>('RMQ_EXCHANGE'),
|
||||
routingKey: 'logging.configuration.delete.crit',
|
||||
},
|
||||
loggingConfigurationReadWarning: {
|
||||
exchange: configService.get<string>('RMQ_EXCHANGE'),
|
||||
routingKey: 'logging.configuration.read.warning',
|
||||
},
|
||||
loggingConfigurationUpdateInfo: {
|
||||
exchange: configService.get<string>('RMQ_EXCHANGE'),
|
||||
routingKey: 'logging.configuration.update.info',
|
||||
},
|
||||
loggingConfigurationUpdateCrit: {
|
||||
exchange: configService.get<string>('RMQ_EXCHANGE'),
|
||||
routingKey: 'logging.configuration.update.crit',
|
||||
},
|
||||
loggingTerritoryCreateInfo: {
|
||||
exchange: configService.get<string>('RMQ_EXCHANGE'),
|
||||
routingKey: 'logging.territory.create.info',
|
||||
},
|
||||
loggingTerritoryCreateWarning: {
|
||||
exchange: configService.get<string>('RMQ_EXCHANGE'),
|
||||
routingKey: 'logging.territory.create.warning',
|
||||
},
|
||||
loggingTerritoryCreateCrit: {
|
||||
exchange: configService.get<string>('RMQ_EXCHANGE'),
|
||||
routingKey: 'logging.territory.create.crit',
|
||||
},
|
||||
loggingTerritoryDeleteInfo: {
|
||||
exchange: configService.get<string>('RMQ_EXCHANGE'),
|
||||
routingKey: 'logging.territory.delete.info',
|
||||
},
|
||||
loggingTerritoryDeleteCrit: {
|
||||
exchange: configService.get<string>('RMQ_EXCHANGE'),
|
||||
routingKey: 'logging.territory.delete.crit',
|
||||
},
|
||||
loggingTerritoryReadWarning: {
|
||||
exchange: configService.get<string>('RMQ_EXCHANGE'),
|
||||
routingKey: 'logging.territory.read.warning',
|
||||
},
|
||||
loggingTerritoryUpdateInfo: {
|
||||
exchange: configService.get<string>('RMQ_EXCHANGE'),
|
||||
routingKey: 'logging.territory.update.info',
|
||||
},
|
||||
loggingTerritoryUpdateCrit: {
|
||||
exchange: configService.get<string>('RMQ_EXCHANGE'),
|
||||
routingKey: 'logging.territory.update.crit',
|
||||
},
|
||||
loggingUserCreateInfo: {
|
||||
exchange: configService.get<string>('RMQ_EXCHANGE'),
|
||||
routingKey: 'logging.user.create.info',
|
||||
},
|
||||
loggingUserCreateWarning: {
|
||||
exchange: configService.get<string>('RMQ_EXCHANGE'),
|
||||
routingKey: 'logging.user.create.warning',
|
||||
},
|
||||
loggingUserCreateCrit: {
|
||||
exchange: configService.get<string>('RMQ_EXCHANGE'),
|
||||
routingKey: 'logging.user.create.crit',
|
||||
},
|
||||
loggingUserDeleteInfo: {
|
||||
exchange: configService.get<string>('RMQ_EXCHANGE'),
|
||||
routingKey: 'logging.user.delete.info',
|
||||
},
|
||||
loggingUserDeleteCrit: {
|
||||
exchange: configService.get<string>('RMQ_EXCHANGE'),
|
||||
routingKey: 'logging.user.delete.crit',
|
||||
},
|
||||
loggingUserReadWarning: {
|
||||
exchange: configService.get<string>('RMQ_EXCHANGE'),
|
||||
routingKey: 'logging.user.read.warning',
|
||||
},
|
||||
loggingUserUpdateInfo: {
|
||||
exchange: configService.get<string>('RMQ_EXCHANGE'),
|
||||
routingKey: 'logging.user.update.info',
|
||||
},
|
||||
loggingUserUpdateCrit: {
|
||||
exchange: configService.get<string>('RMQ_EXCHANGE'),
|
||||
routingKey: 'logging.user.update.crit',
|
||||
},
|
||||
},
|
||||
uri: configService.get<string>('RMQ_URI'),
|
||||
enableControllerDiscovery: true,
|
||||
}),
|
||||
|
|
|
@ -12,9 +12,7 @@ export class AuthController {
|
|||
) {}
|
||||
|
||||
@RabbitSubscribe({
|
||||
exchange: 'logging',
|
||||
routingKey: 'auth.create.crit',
|
||||
queue: 'logging-auth-create-crit',
|
||||
name: 'loggingAuthCreateCrit',
|
||||
})
|
||||
public async authCreatedCriticalHandler(message: string) {
|
||||
this.logger.configure(
|
||||
|
@ -24,9 +22,7 @@ export class AuthController {
|
|||
}
|
||||
|
||||
@RabbitSubscribe({
|
||||
exchange: 'logging',
|
||||
routingKey: 'auth.delete.crit',
|
||||
queue: 'logging-auth-delete-crit',
|
||||
name: 'loggingAuthDeleteCrit',
|
||||
})
|
||||
public async authDeletedCriticalHandler(message: string) {
|
||||
this.logger.configure(
|
||||
|
@ -36,9 +32,7 @@ export class AuthController {
|
|||
}
|
||||
|
||||
@RabbitSubscribe({
|
||||
exchange: 'logging',
|
||||
routingKey: 'auth.username.add.warning',
|
||||
queue: 'logging-auth-username-add-warning',
|
||||
name: 'loggingAuthUsernameAddWarning',
|
||||
})
|
||||
public async authUsernameAddedWarningHandler(message: string) {
|
||||
this.logger.configure(
|
||||
|
@ -48,9 +42,7 @@ export class AuthController {
|
|||
}
|
||||
|
||||
@RabbitSubscribe({
|
||||
exchange: 'logging',
|
||||
routingKey: 'auth.username.delete.warning',
|
||||
queue: 'logging-auth-username-delete-warning',
|
||||
name: 'loggingAuthUsernameDeleteWarning',
|
||||
})
|
||||
public async authUsernameDeletedWarningHandler(message: string) {
|
||||
this.logger.configure(
|
||||
|
@ -60,9 +52,7 @@ export class AuthController {
|
|||
}
|
||||
|
||||
@RabbitSubscribe({
|
||||
exchange: 'logging',
|
||||
routingKey: 'auth.password.update.warning',
|
||||
queue: 'logging-auth-password-update-warning',
|
||||
name: 'loggingAuthPasswordUpdateWarning',
|
||||
})
|
||||
public async authPasswordUpdatedWarningHandler(message: string) {
|
||||
this.logger.configure(
|
||||
|
@ -72,9 +62,7 @@ export class AuthController {
|
|||
}
|
||||
|
||||
@RabbitSubscribe({
|
||||
exchange: 'logging',
|
||||
routingKey: 'auth.username.update.warning',
|
||||
queue: 'logging-auth-username-update-warning',
|
||||
name: 'loggingAuthUsernameUpdateWarning',
|
||||
})
|
||||
public async authUsernameUpdatedWarningHandler(message: string) {
|
||||
this.logger.configure(
|
||||
|
|
|
@ -12,9 +12,7 @@ export class ConfigurationController {
|
|||
) {}
|
||||
|
||||
@RabbitSubscribe({
|
||||
exchange: 'logging',
|
||||
routingKey: 'configuration.create.info',
|
||||
queue: 'logging-configuration-create-info',
|
||||
name: 'loggingConfigurationCreateInfo',
|
||||
})
|
||||
public async configurationCreatedInfoHandler(message: string) {
|
||||
this.logger.configure(
|
||||
|
@ -24,9 +22,7 @@ export class ConfigurationController {
|
|||
}
|
||||
|
||||
@RabbitSubscribe({
|
||||
exchange: 'logging',
|
||||
routingKey: 'configuration.create.warning',
|
||||
queue: 'logging-configuration-create-warning',
|
||||
name: 'loggingConfigurationCreateWarning',
|
||||
})
|
||||
public async configurationCreatedWarningHandler(message: string) {
|
||||
this.logger.configure(
|
||||
|
@ -36,9 +32,7 @@ export class ConfigurationController {
|
|||
}
|
||||
|
||||
@RabbitSubscribe({
|
||||
exchange: 'logging',
|
||||
routingKey: 'configuration.create.crit',
|
||||
queue: 'logging-configuration-create-crit',
|
||||
name: 'loggingConfigurationCreateCrit',
|
||||
})
|
||||
public async configurationCreatedCriticalHandler(message: string) {
|
||||
this.logger.configure(
|
||||
|
@ -48,9 +42,7 @@ export class ConfigurationController {
|
|||
}
|
||||
|
||||
@RabbitSubscribe({
|
||||
exchange: 'logging',
|
||||
routingKey: 'configuration.delete.info',
|
||||
queue: 'logging-configuration-delete-info',
|
||||
name: 'loggingConfigurationDeleteInfo',
|
||||
})
|
||||
public async configurationDeletedInfoHandler(message: string) {
|
||||
this.logger.configure(
|
||||
|
@ -60,9 +52,7 @@ export class ConfigurationController {
|
|||
}
|
||||
|
||||
@RabbitSubscribe({
|
||||
exchange: 'logging',
|
||||
routingKey: 'configuration.delete.crit',
|
||||
queue: 'logging-configuration-delete-crit',
|
||||
name: 'loggingConfigurationDeleteCrit',
|
||||
})
|
||||
public async configurationDeletedCriticalHandler(message: string) {
|
||||
this.logger.configure(
|
||||
|
@ -72,9 +62,7 @@ export class ConfigurationController {
|
|||
}
|
||||
|
||||
@RabbitSubscribe({
|
||||
exchange: 'logging',
|
||||
routingKey: 'configuration.read.warning',
|
||||
queue: 'logging-configuration-read-warning',
|
||||
name: 'loggingConfigurationReadWarning',
|
||||
})
|
||||
public async configurationReadWarningHandler(message: string) {
|
||||
this.logger.configure(
|
||||
|
@ -84,9 +72,7 @@ export class ConfigurationController {
|
|||
}
|
||||
|
||||
@RabbitSubscribe({
|
||||
exchange: 'logging',
|
||||
routingKey: 'configuration.update.info',
|
||||
queue: 'logging-configuration-update-info',
|
||||
name: 'loggingConfigurationUpdateInfo',
|
||||
})
|
||||
public async configurationUpdatedInfoHandler(message: string) {
|
||||
this.logger.configure(
|
||||
|
@ -96,9 +82,7 @@ export class ConfigurationController {
|
|||
}
|
||||
|
||||
@RabbitSubscribe({
|
||||
exchange: 'logging',
|
||||
routingKey: 'configuration.update.crit',
|
||||
queue: 'logging-configuration-update-crit',
|
||||
name: 'loggingConfigurationUpdateCrit',
|
||||
})
|
||||
public async configurationUpdatedCriticalHandler(message: string) {
|
||||
this.logger.configure(
|
||||
|
|
|
@ -12,9 +12,7 @@ export class TerritoryController {
|
|||
) {}
|
||||
|
||||
@RabbitSubscribe({
|
||||
exchange: 'logging',
|
||||
routingKey: 'territory.create.info',
|
||||
queue: 'logging-territory-create-info',
|
||||
name: 'loggingTerritoryCreateInfo',
|
||||
})
|
||||
public async territoryCreatedInfoHandler(message: string) {
|
||||
this.logger.configure(
|
||||
|
@ -24,9 +22,7 @@ export class TerritoryController {
|
|||
}
|
||||
|
||||
@RabbitSubscribe({
|
||||
exchange: 'logging',
|
||||
routingKey: 'territory.create.warning',
|
||||
queue: 'logging-territory-create-warning',
|
||||
name: 'loggingTerritoryCreateWarning',
|
||||
})
|
||||
public async territoryCreatedWarningHandler(message: string) {
|
||||
this.logger.configure(
|
||||
|
@ -36,9 +32,7 @@ export class TerritoryController {
|
|||
}
|
||||
|
||||
@RabbitSubscribe({
|
||||
exchange: 'logging',
|
||||
routingKey: 'territory.create.crit',
|
||||
queue: 'logging-territory-create-crit',
|
||||
name: 'loggingTerritoryCreateCrit',
|
||||
})
|
||||
public async territoryCreatedCriticalHandler(message: string) {
|
||||
this.logger.configure(
|
||||
|
@ -48,9 +42,7 @@ export class TerritoryController {
|
|||
}
|
||||
|
||||
@RabbitSubscribe({
|
||||
exchange: 'logging',
|
||||
routingKey: 'territory.delete.info',
|
||||
queue: 'logging-territory-delete-info',
|
||||
name: 'loggingTerritoryDeleteInfo',
|
||||
})
|
||||
public async territoryDeletedInfoHandler(message: string) {
|
||||
this.logger.configure(
|
||||
|
@ -60,9 +52,7 @@ export class TerritoryController {
|
|||
}
|
||||
|
||||
@RabbitSubscribe({
|
||||
exchange: 'logging',
|
||||
routingKey: 'territory.delete.crit',
|
||||
queue: 'logging-territory-delete-crit',
|
||||
name: 'loggingTerritoryDeleteCrit',
|
||||
})
|
||||
public async territoryDeletedCriticalHandler(message: string) {
|
||||
this.logger.configure(
|
||||
|
@ -72,9 +62,7 @@ export class TerritoryController {
|
|||
}
|
||||
|
||||
@RabbitSubscribe({
|
||||
exchange: 'logging',
|
||||
routingKey: 'territory.read.warning',
|
||||
queue: 'logging-territory-read-warning',
|
||||
name: 'loggingTerritoryReadWarning',
|
||||
})
|
||||
public async territoryReadWarningHandler(message: string) {
|
||||
this.logger.configure(
|
||||
|
@ -84,9 +72,7 @@ export class TerritoryController {
|
|||
}
|
||||
|
||||
@RabbitSubscribe({
|
||||
exchange: 'logging',
|
||||
routingKey: 'territory.update.info',
|
||||
queue: 'logging-territory-update-info',
|
||||
name: 'loggingTerritoryUpdateInfo',
|
||||
})
|
||||
public async territoryUpdatedInfoHandler(message: string) {
|
||||
this.logger.configure(
|
||||
|
@ -96,9 +82,7 @@ export class TerritoryController {
|
|||
}
|
||||
|
||||
@RabbitSubscribe({
|
||||
exchange: 'logging',
|
||||
routingKey: 'territory.update.crit',
|
||||
queue: 'logging-territory-update-crit',
|
||||
name: 'loggingTerritoryUpdateCrit',
|
||||
})
|
||||
public async territoryUpdatedCriticalHandler(message: string) {
|
||||
this.logger.configure(
|
||||
|
|
|
@ -12,9 +12,7 @@ export class UserController {
|
|||
) {}
|
||||
|
||||
@RabbitSubscribe({
|
||||
exchange: 'logging',
|
||||
routingKey: 'user.create.info',
|
||||
queue: 'logging-user-create-info',
|
||||
name: 'loggingUserCreateInfo',
|
||||
})
|
||||
public async userCreatedInfoHandler(message: string) {
|
||||
this.logger.configure(loggerOptions('user', level.info, 'info', 'create'));
|
||||
|
@ -22,9 +20,7 @@ export class UserController {
|
|||
}
|
||||
|
||||
@RabbitSubscribe({
|
||||
exchange: 'logging',
|
||||
routingKey: 'user.create.warning',
|
||||
queue: 'logging-user-create-warning',
|
||||
name: 'loggingUserCreateWarning',
|
||||
})
|
||||
public async userCreatedWarningHandler(message: string) {
|
||||
this.logger.configure(
|
||||
|
@ -34,9 +30,7 @@ export class UserController {
|
|||
}
|
||||
|
||||
@RabbitSubscribe({
|
||||
exchange: 'logging',
|
||||
routingKey: 'user.create.crit',
|
||||
queue: 'logging-user-create-crit',
|
||||
name: 'loggingUserCreateCrit',
|
||||
})
|
||||
public async userCreatedCriticalHandler(message: string) {
|
||||
this.logger.configure(
|
||||
|
@ -46,9 +40,7 @@ export class UserController {
|
|||
}
|
||||
|
||||
@RabbitSubscribe({
|
||||
exchange: 'logging',
|
||||
routingKey: 'user.delete.info',
|
||||
queue: 'logging-user-delete-info',
|
||||
name: 'loggingUserDeleteInfo',
|
||||
})
|
||||
public async userDeletedInfoHandler(message: string) {
|
||||
this.logger.configure(loggerOptions('user', level.info, 'info', 'delete'));
|
||||
|
@ -56,9 +48,7 @@ export class UserController {
|
|||
}
|
||||
|
||||
@RabbitSubscribe({
|
||||
exchange: 'logging',
|
||||
routingKey: 'user.delete.crit',
|
||||
queue: 'logging-user-delete-crit',
|
||||
name: 'loggingUserDeleteCrit',
|
||||
})
|
||||
public async userDeletedCriticalHandler(message: string) {
|
||||
this.logger.configure(
|
||||
|
@ -68,9 +58,7 @@ export class UserController {
|
|||
}
|
||||
|
||||
@RabbitSubscribe({
|
||||
exchange: 'logging',
|
||||
routingKey: 'user.read.warning',
|
||||
queue: 'logging-user-read-warning',
|
||||
name: 'loggingUserReadWarning',
|
||||
})
|
||||
public async userReadWarningHandler(message: string) {
|
||||
this.logger.configure(
|
||||
|
@ -80,9 +68,7 @@ export class UserController {
|
|||
}
|
||||
|
||||
@RabbitSubscribe({
|
||||
exchange: 'logging',
|
||||
routingKey: 'user.update.info',
|
||||
queue: 'logging-user-update-info',
|
||||
name: 'loggingUserUpdateInfo',
|
||||
})
|
||||
public async userUpdatedInfoHandler(message: string) {
|
||||
this.logger.configure(loggerOptions('user', level.info, 'info', 'update'));
|
||||
|
@ -90,9 +76,7 @@ export class UserController {
|
|||
}
|
||||
|
||||
@RabbitSubscribe({
|
||||
exchange: 'logging',
|
||||
routingKey: 'user.update.crit',
|
||||
queue: 'logging-user-update-crit',
|
||||
name: 'loggingUserUpdateCrit',
|
||||
})
|
||||
public async userUpdatedCriticalHandler(message: string) {
|
||||
this.logger.configure(
|
||||
|
|
Loading…
Reference in New Issue