mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-13 15:14:49 -06:00
feat(rabbitmq): Add prefix key configuration for queue names
This commit is contained in:
parent
f11e3247f0
commit
fa19c7fa89
@ -49,6 +49,8 @@ RABBITMQ_URI=amqp://localhost
|
||||
RABBITMQ_EXCHANGE_NAME=evolution
|
||||
# Global events - By enabling this variable, events from all instances are sent in the same event queue.
|
||||
RABBITMQ_GLOBAL_ENABLED=false
|
||||
# Prefix key to queue name
|
||||
RABBITMQ_PREFIX_KEY=evolution
|
||||
# Choose the events you want to send to RabbitMQ
|
||||
RABBITMQ_EVENTS_APPLICATION_STARTUP=false
|
||||
RABBITMQ_EVENTS_INSTANCE_CREATE=false
|
||||
|
@ -1,3 +1,9 @@
|
||||
# 2.2.2 (develop)
|
||||
|
||||
### Features
|
||||
|
||||
* Added prefix key to queue name in RabbitMQ
|
||||
|
||||
# 2.2.1 (2025-01-22 14:37)
|
||||
|
||||
### Features
|
||||
|
@ -87,6 +87,7 @@ export class RabbitmqController extends EventController implements EventControll
|
||||
const rabbitmqLocal = instanceRabbitmq?.events;
|
||||
const rabbitmqGlobal = configService.get<Rabbitmq>('RABBITMQ').GLOBAL_ENABLED;
|
||||
const rabbitmqEvents = configService.get<Rabbitmq>('RABBITMQ').EVENTS;
|
||||
const prefixKey = configService.get<Rabbitmq>('RABBITMQ').PREFIX_KEY;
|
||||
const rabbitmqExchangeName = configService.get<Rabbitmq>('RABBITMQ').EXCHANGE_NAME;
|
||||
const we = event.replace(/[.-]/gm, '_').toUpperCase();
|
||||
const logEnabled = configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS');
|
||||
@ -159,7 +160,9 @@ export class RabbitmqController extends EventController implements EventControll
|
||||
autoDelete: false,
|
||||
});
|
||||
|
||||
const queueName = event;
|
||||
const queueName = prefixKey
|
||||
? `${prefixKey}.${event.replace(/_/g, '.').toLowerCase()}`
|
||||
: event.replace(/_/g, '.').toLowerCase();
|
||||
|
||||
await this.amqpChannel.assertQueue(queueName, {
|
||||
durable: true,
|
||||
@ -195,6 +198,7 @@ export class RabbitmqController extends EventController implements EventControll
|
||||
|
||||
const rabbitmqExchangeName = configService.get<Rabbitmq>('RABBITMQ').EXCHANGE_NAME;
|
||||
const events = configService.get<Rabbitmq>('RABBITMQ').EVENTS;
|
||||
const prefixKey = configService.get<Rabbitmq>('RABBITMQ').PREFIX_KEY;
|
||||
|
||||
if (!events) {
|
||||
this.logger.warn('No events to initialize on AMQP');
|
||||
@ -207,7 +211,10 @@ export class RabbitmqController extends EventController implements EventControll
|
||||
eventKeys.forEach((event) => {
|
||||
if (events[event] === false) return;
|
||||
|
||||
const queueName = `${event.replace(/_/g, '.').toLowerCase()}`;
|
||||
const queueName =
|
||||
prefixKey !== ''
|
||||
? `${prefixKey}.${event.replace(/_/g, '.').toLowerCase()}`
|
||||
: `${event.replace(/_/g, '.').toLowerCase()}`;
|
||||
const exchangeName = rabbitmqExchangeName;
|
||||
|
||||
this.amqpChannel.assertExchange(exchangeName, 'topic', {
|
||||
|
@ -97,6 +97,7 @@ export type Rabbitmq = {
|
||||
EXCHANGE_NAME: string;
|
||||
GLOBAL_ENABLED: boolean;
|
||||
EVENTS: EventsRabbitmq;
|
||||
PREFIX_KEY: string;
|
||||
};
|
||||
|
||||
export type Sqs = {
|
||||
@ -355,6 +356,7 @@ export class ConfigService {
|
||||
RABBITMQ: {
|
||||
ENABLED: process.env?.RABBITMQ_ENABLED === 'true',
|
||||
GLOBAL_ENABLED: process.env?.RABBITMQ_GLOBAL_ENABLED === 'true',
|
||||
PREFIX_KEY: process.env?.RABBITMQ_PREFIX_KEY || 'evolution',
|
||||
EXCHANGE_NAME: process.env?.RABBITMQ_EXCHANGE_NAME || 'evolution_exchange',
|
||||
URI: process.env.RABBITMQ_URI || '',
|
||||
EVENTS: {
|
||||
|
Loading…
Reference in New Issue
Block a user