mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-24 17:38:40 -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 = () => {
|
export const initGlobalQueues = () => {
|
||||||
logger.info('Initializing global queues');
|
logger.info('Initializing global queues');
|
||||||
const events = configService.get<Rabbitmq>('RABBITMQ').EVENTS;
|
const events = configService.get<Rabbitmq>('RABBITMQ').EVENTS;
|
||||||
|
const prefixKey = configService.get<Rabbitmq>('RABBITMQ').PREFIX_KEY;
|
||||||
|
|
||||||
if (!events) {
|
if (!events) {
|
||||||
logger.warn('No events to initialize on AMQP');
|
logger.warn('No events to initialize on AMQP');
|
||||||
@ -56,7 +57,11 @@ export const initGlobalQueues = () => {
|
|||||||
eventKeys.forEach((event) => {
|
eventKeys.forEach((event) => {
|
||||||
if (events[event] === false) return;
|
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 amqp = getAMQP();
|
||||||
const exchangeName = 'evolution_exchange';
|
const exchangeName = 'evolution_exchange';
|
||||||
|
|
||||||
|
@ -778,6 +778,7 @@ export class ChannelStartupService {
|
|||||||
|
|
||||||
if (rabbitmqGlobal && rabbitmqEvents[we] && amqp) {
|
if (rabbitmqGlobal && rabbitmqEvents[we] && amqp) {
|
||||||
const exchangeName = 'evolution_exchange';
|
const exchangeName = 'evolution_exchange';
|
||||||
|
const prefixKey = this.configService.get<Rabbitmq>('RABBITMQ').PREFIX_KEY;
|
||||||
|
|
||||||
let retry = 0;
|
let retry = 0;
|
||||||
|
|
||||||
@ -788,7 +789,10 @@ export class ChannelStartupService {
|
|||||||
autoDelete: false,
|
autoDelete: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const queueName = event;
|
const queueName =
|
||||||
|
prefixKey !== ''
|
||||||
|
? `${prefixKey}.${event.replace(/_/g, '.').toLowerCase()}`
|
||||||
|
: `${event.replace(/_/g, '.').toLowerCase()}`;
|
||||||
|
|
||||||
await amqp.assertQueue(queueName, {
|
await amqp.assertQueue(queueName, {
|
||||||
durable: true,
|
durable: true,
|
||||||
|
@ -104,6 +104,7 @@ export type Rabbitmq = {
|
|||||||
ENABLED: boolean;
|
ENABLED: boolean;
|
||||||
URI: string;
|
URI: string;
|
||||||
EXCHANGE_NAME: string;
|
EXCHANGE_NAME: string;
|
||||||
|
PREFIX_KEY?: string;
|
||||||
GLOBAL_ENABLED: boolean;
|
GLOBAL_ENABLED: boolean;
|
||||||
EVENTS: EventsRabbitmq;
|
EVENTS: EventsRabbitmq;
|
||||||
};
|
};
|
||||||
@ -323,6 +324,7 @@ export class ConfigService {
|
|||||||
ENABLED: process.env?.RABBITMQ_ENABLED === 'true',
|
ENABLED: process.env?.RABBITMQ_ENABLED === 'true',
|
||||||
GLOBAL_ENABLED: process.env?.RABBITMQ_GLOBAL_ENABLED === 'true',
|
GLOBAL_ENABLED: process.env?.RABBITMQ_GLOBAL_ENABLED === 'true',
|
||||||
EXCHANGE_NAME: process.env?.RABBITMQ_EXCHANGE_NAME || 'evolution_exchange',
|
EXCHANGE_NAME: process.env?.RABBITMQ_EXCHANGE_NAME || 'evolution_exchange',
|
||||||
|
PREFIX_KEY: process.env?.RABBITMQ_PREFIX_KEY || '',
|
||||||
URI: process.env.RABBITMQ_URI || '',
|
URI: process.env.RABBITMQ_URI || '',
|
||||||
EVENTS: {
|
EVENTS: {
|
||||||
APPLICATION_STARTUP: process.env?.RABBITMQ_EVENTS_APPLICATION_STARTUP === 'true',
|
APPLICATION_STARTUP: process.env?.RABBITMQ_EVENTS_APPLICATION_STARTUP === 'true',
|
||||||
|
@ -89,6 +89,7 @@ RABBITMQ:
|
|||||||
ENABLED: false
|
ENABLED: false
|
||||||
URI: "amqp://guest:guest@localhost:5672"
|
URI: "amqp://guest:guest@localhost:5672"
|
||||||
EXCHANGE_NAME: evolution_exchange
|
EXCHANGE_NAME: evolution_exchange
|
||||||
|
PREFIX_KEY: evolution
|
||||||
GLOBAL_ENABLED: true
|
GLOBAL_ENABLED: true
|
||||||
EVENTS:
|
EVENTS:
|
||||||
APPLICATION_STARTUP: false
|
APPLICATION_STARTUP: false
|
||||||
|
Loading…
Reference in New Issue
Block a user