mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-22 20:12:02 -06:00
feat: Add PREFIX_KEY configuration for RabbitMQ integration
- Introduced a new optional PREFIX_KEY in the RabbitMQ configuration to allow custom queue naming. - Updated the AMQP server and channel service to utilize PREFIX_KEY when initializing queues. - Modified the dev environment configuration to include PREFIX_KEY. This enhancement improves the flexibility of queue naming in RabbitMQ, facilitating better organization and management of queues.
This commit is contained in:
parent
ebd70fe454
commit
ca474236b0
@ -45,6 +45,7 @@ export const getAMQP = (): amqp.Channel | null => {
|
||||
export const initGlobalQueues = () => {
|
||||
logger.info('Initializing global queues');
|
||||
const events = configService.get<Rabbitmq>('RABBITMQ').EVENTS;
|
||||
const prefixKey = configService.get<Rabbitmq>('RABBITMQ').PREFIX_KEY;
|
||||
|
||||
if (!events) {
|
||||
logger.warn('No events to initialize on AMQP');
|
||||
@ -56,7 +57,11 @@ export const initGlobalQueues = () => {
|
||||
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 amqp = getAMQP();
|
||||
const exchangeName = 'evolution_exchange';
|
||||
|
||||
|
@ -778,6 +778,7 @@ export class ChannelStartupService {
|
||||
|
||||
if (rabbitmqGlobal && rabbitmqEvents[we] && amqp) {
|
||||
const exchangeName = 'evolution_exchange';
|
||||
const prefixKey = this.configService.get<Rabbitmq>('RABBITMQ').PREFIX_KEY;
|
||||
|
||||
let retry = 0;
|
||||
|
||||
@ -788,7 +789,10 @@ export class ChannelStartupService {
|
||||
autoDelete: false,
|
||||
});
|
||||
|
||||
const queueName = event;
|
||||
const queueName =
|
||||
prefixKey !== ''
|
||||
? `${prefixKey}.${event.replace(/_/g, '.').toLowerCase()}`
|
||||
: `${event.replace(/_/g, '.').toLowerCase()}`;
|
||||
|
||||
await amqp.assertQueue(queueName, {
|
||||
durable: true,
|
||||
|
@ -104,6 +104,7 @@ export type Rabbitmq = {
|
||||
ENABLED: boolean;
|
||||
URI: string;
|
||||
EXCHANGE_NAME: string;
|
||||
PREFIX_KEY?: string;
|
||||
GLOBAL_ENABLED: boolean;
|
||||
EVENTS: EventsRabbitmq;
|
||||
};
|
||||
@ -323,6 +324,7 @@ export class ConfigService {
|
||||
ENABLED: process.env?.RABBITMQ_ENABLED === 'true',
|
||||
GLOBAL_ENABLED: process.env?.RABBITMQ_GLOBAL_ENABLED === 'true',
|
||||
EXCHANGE_NAME: process.env?.RABBITMQ_EXCHANGE_NAME || 'evolution_exchange',
|
||||
PREFIX_KEY: process.env?.RABBITMQ_PREFIX_KEY || '',
|
||||
URI: process.env.RABBITMQ_URI || '',
|
||||
EVENTS: {
|
||||
APPLICATION_STARTUP: process.env?.RABBITMQ_EVENTS_APPLICATION_STARTUP === 'true',
|
||||
|
@ -89,6 +89,7 @@ RABBITMQ:
|
||||
ENABLED: false
|
||||
URI: "amqp://guest:guest@localhost:5672"
|
||||
EXCHANGE_NAME: evolution_exchange
|
||||
PREFIX_KEY: evolution
|
||||
GLOBAL_ENABLED: true
|
||||
EVENTS:
|
||||
APPLICATION_STARTUP: false
|
||||
|
Loading…
Reference in New Issue
Block a user