refactor message broker

This commit is contained in:
sbriat 2023-03-15 17:38:55 +01:00
parent 705de1bcf8
commit 8ddc65c9fd
2 changed files with 18 additions and 10 deletions

View File

@ -16,9 +16,7 @@ export class ConfigurationMessagerController {
) {}
@RabbitSubscribe({
exchange: 'configuration',
routingKey: ['create', 'update'],
queue: 'user-configuration-update',
name: 'setConfiguration',
})
public async setConfigurationHandler(message: string) {
const configuration: Configuration = JSON.parse(message);
@ -38,9 +36,7 @@ export class ConfigurationMessagerController {
}
@RabbitSubscribe({
exchange: 'configuration',
routingKey: 'delete',
queue: 'user-configuration-delete',
name: 'deleteConfiguration',
})
public async configurationDeletedHandler(message: string) {
const deletedConfiguration: Configuration = JSON.parse(message);
@ -58,9 +54,7 @@ export class ConfigurationMessagerController {
}
@RabbitSubscribe({
exchange: 'configuration',
routingKey: 'propagate',
queue: 'user-configuration-propagate',
name: 'propagateConfiguration',
})
public async propagateConfigurationsHandler(message: string) {
const configurations: Array<Configuration> = JSON.parse(message);

View File

@ -32,10 +32,24 @@ import { SetConfigurationUseCase } from './domain/usecases/set-configuration.use
): Promise<RabbitMQConfig> => ({
exchanges: [
{
name: 'configuration',
name: configService.get<string>('RMQ_EXCHANGE'),
type: 'topic',
},
],
handlers: {
setConfiguration: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: ['configuration.create', 'configuration.update'],
},
deleteConfiguration: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'configuration.delete',
},
propagateConfiguration: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'configuration.propagate',
},
},
uri: configService.get<string>('RMQ_URI'),
connectionInitOptions: { wait: false },
enableControllerDiscovery: true,