mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-09 01:49:37 -06:00
feat/force to save all evolution events in a single SQS queue
This commit is contained in:
parent
cca929e7fc
commit
23cd6d2fd8
@ -98,6 +98,7 @@ SQS_ACCOUNT_ID=
|
||||
SQS_REGION=
|
||||
|
||||
SQS_GLOBAL_ENABLED=false
|
||||
SQS_GLOBAL_FORCE_SINGLE_QUEUE=false
|
||||
SQS_GLOBAL_APPLICATION_STARTUP=false
|
||||
SQS_GLOBAL_CALL=false
|
||||
SQS_GLOBAL_CHATS_DELETE=false
|
||||
|
||||
@ -118,8 +118,11 @@ export class SqsController extends EventController implements EventControllerInt
|
||||
}
|
||||
|
||||
if (Array.isArray(sqsEvents) && sqsEvents.includes(we)) {
|
||||
const eventFormatted = `${event.replace('.', '_').toLowerCase()}`;
|
||||
const prefixName = sqsConfig.GLOBAL_ENABLED ? sqsConfig.GLOBAL_PREFIX_NAME : instanceName;
|
||||
const eventFormatted =
|
||||
sqsConfig.GLOBAL_ENABLED && sqsConfig.GLOBAL_FORCE_SINGLE_QUEUE
|
||||
? 'singlequeue'
|
||||
: `${event.replace('.', '_').toLowerCase()}`;
|
||||
const queueName = `${prefixName}_${eventFormatted}.fifo`;
|
||||
|
||||
const sqsUrl = `https://sqs.${sqsConfig.REGION}.amazonaws.com/${sqsConfig.ACCOUNT_ID}/${queueName}`;
|
||||
@ -199,12 +202,15 @@ export class SqsController extends EventController implements EventControllerInt
|
||||
|
||||
private async saveQueues(prefixName: string, events: string[], enable: boolean) {
|
||||
if (enable) {
|
||||
const sqsConfig = configService.get<Sqs>('SQS');
|
||||
const eventsFinded = await this.listQueues(prefixName);
|
||||
console.log('eventsFinded', eventsFinded);
|
||||
|
||||
for (const event of events) {
|
||||
const normalizedEvent = event.toLowerCase();
|
||||
|
||||
const normalizedEvent =
|
||||
sqsConfig.GLOBAL_ENABLED && sqsConfig.GLOBAL_FORCE_SINGLE_QUEUE
|
||||
? 'singlequeue'
|
||||
: event.toLowerCase();
|
||||
if (eventsFinded.includes(normalizedEvent)) {
|
||||
this.logger.info(`A queue para o evento "${normalizedEvent}" já existe. Ignorando criação.`);
|
||||
continue;
|
||||
@ -212,7 +218,7 @@ export class SqsController extends EventController implements EventControllerInt
|
||||
|
||||
const queueName = `${prefixName}_${normalizedEvent}.fifo`;
|
||||
try {
|
||||
const isGlobalEnabled = configService.get<Sqs>('SQS').GLOBAL_ENABLED;
|
||||
const isGlobalEnabled = sqsConfig.GLOBAL_ENABLED;
|
||||
const createCommand = new CreateQueueCommand({
|
||||
QueueName: queueName,
|
||||
Attributes: {
|
||||
@ -226,6 +232,10 @@ export class SqsController extends EventController implements EventControllerInt
|
||||
} catch (err: any) {
|
||||
this.logger.error(`Erro ao criar queue ${queueName}: ${err.message}`);
|
||||
}
|
||||
|
||||
if (sqsConfig.GLOBAL_ENABLED && sqsConfig.GLOBAL_FORCE_SINGLE_QUEUE) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,6 +115,7 @@ export type Nats = {
|
||||
export type Sqs = {
|
||||
ENABLED: boolean;
|
||||
GLOBAL_ENABLED: boolean;
|
||||
GLOBAL_FORCE_SINGLE_QUEUE: boolean;
|
||||
GLOBAL_PREFIX_NAME: string;
|
||||
ACCESS_KEY_ID: string;
|
||||
SECRET_ACCESS_KEY: string;
|
||||
@ -500,6 +501,7 @@ export class ConfigService {
|
||||
SQS: {
|
||||
ENABLED: process.env?.SQS_ENABLED === 'true',
|
||||
GLOBAL_ENABLED: process.env?.SQS_GLOBAL_ENABLED === 'true',
|
||||
GLOBAL_FORCE_SINGLE_QUEUE: process.env?.SQS_GLOBAL_FORCE_SINGLE_QUEUE === 'true',
|
||||
GLOBAL_PREFIX_NAME: process.env?.SQS_GLOBAL_PREFIX_NAME || 'global',
|
||||
ACCESS_KEY_ID: process.env.SQS_ACCESS_KEY_ID || '',
|
||||
SECRET_ACCESS_KEY: process.env.SQS_SECRET_ACCESS_KEY || '',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user