diff --git a/Docker/.env.example b/Docker/.env.example index 6c62b8bc..0f4f2972 100644 --- a/Docker/.env.example +++ b/Docker/.env.example @@ -46,6 +46,9 @@ REDIS_ENABLED=true REDIS_URI=redis://redis:6379 REDIS_PREFIX_KEY=evdocker +RABBITMQ_ENABLED=true +RABBITMQ_URI=amqp://guest:guest@rabbitmq:5672 + # Global Webhook Settings # Each instance's Webhook URL and events will be requested at the time it is created ## Define a global webhook that will listen for enabled events from all instances diff --git a/Dockerfile b/Dockerfile index 94f885a4..4484b8b8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -51,6 +51,9 @@ ENV REDIS_ENABLED=false ENV REDIS_URI=redis://redis:6379 ENV REDIS_PREFIX_KEY=evolution +ENV RABBITMQ_ENABLED=false +ENV RABBITMQ_URI=amqp://guest:guest@rabbitmq:5672 + ENV WEBHOOK_GLOBAL_URL= ENV WEBHOOK_GLOBAL_ENABLED=false diff --git a/src/config/env.config.ts b/src/config/env.config.ts index a7638435..8ddb4e2c 100644 --- a/src/config/env.config.ts +++ b/src/config/env.config.ts @@ -61,6 +61,11 @@ export type Redis = { PREFIX_KEY: string; }; +export type Rabbitmq = { + ENABLED: boolean; + URI: string; +}; + export type EventsWebhook = { APPLICATION_STARTUP: boolean; QRCODE_UPDATED: boolean; @@ -116,6 +121,7 @@ export interface Env { CLEAN_STORE: CleanStoreConf; DATABASE: Database; REDIS: Redis; + RABBITMQ: Rabbitmq; LOG: Log; DEL_INSTANCE: DelInstance; WEBHOOK: Webhook; @@ -201,6 +207,10 @@ export class ConfigService { URI: process.env.REDIS_URI, PREFIX_KEY: process.env.REDIS_PREFIX_KEY, }, + RABBITMQ: { + ENABLED: process.env?.RABBITMQ_ENABLED === 'true', + URI: process.env.RABBITMQ_URI, + }, LOG: { LEVEL: process.env?.LOG_LEVEL.split(',') as LogLevel[], COLOR: process.env?.LOG_COLOR === 'true', diff --git a/src/dev-env.yml b/src/dev-env.yml index ed2df448..02cb0730 100644 --- a/src/dev-env.yml +++ b/src/dev-env.yml @@ -79,6 +79,10 @@ REDIS: URI: "redis://localhost:6379" PREFIX_KEY: "evolution" +RABBITMQ: + ENABLED: false + URI: "amqp://guest:guest@localhost:5672" + # Global Webhook Settings # Each instance's Webhook URL and events will be requested at the time it is created WEBHOOK: diff --git a/src/libs/amqp.server.ts b/src/libs/amqp.server.ts index 55ec4193..9b3e7f7c 100644 --- a/src/libs/amqp.server.ts +++ b/src/libs/amqp.server.ts @@ -1,5 +1,6 @@ import * as amqp from 'amqplib/callback_api'; +import { configService, Rabbitmq } from '../config/env.config'; import { Logger } from '../config/logger.config'; const logger = new Logger('AMQP'); @@ -8,7 +9,8 @@ let amqpChannel: amqp.Channel | null = null; export const initAMQP = () => { return new Promise((resolve, reject) => { - amqp.connect('amqp://admin:admin@localhost:5672', (error, connection) => { + const uri = configService.get('RABBITMQ').URI; + amqp.connect(uri, (error, connection) => { if (error) { reject(error); return; @@ -25,7 +27,7 @@ export const initAMQP = () => { channel.assertExchange(exchangeName, 'topic', { durable: false }); amqpChannel = channel; - logger.log('Serviço do RabbitMQ inicializado com sucesso.'); + logger.log('AMQP initialized'); resolve(); }); });