Skip to content

Commit 55f8e17

Browse files
committed
feat: Added rabbitmq to send events
1 parent ab5289a commit 55f8e17

5 files changed

Lines changed: 24 additions & 2 deletions

File tree

Docker/.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ REDIS_ENABLED=true
4646
REDIS_URI=redis://redis:6379
4747
REDIS_PREFIX_KEY=evdocker
4848

49+
RABBITMQ_ENABLED=true
50+
RABBITMQ_URI=amqp://guest:guest@rabbitmq:5672
51+
4952
# Global Webhook Settings
5053
# Each instance's Webhook URL and events will be requested at the time it is created
5154
## Define a global webhook that will listen for enabled events from all instances

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ ENV REDIS_ENABLED=false
5151
ENV REDIS_URI=redis://redis:6379
5252
ENV REDIS_PREFIX_KEY=evolution
5353

54+
ENV RABBITMQ_ENABLED=false
55+
ENV RABBITMQ_URI=amqp://guest:guest@rabbitmq:5672
56+
5457
ENV WEBHOOK_GLOBAL_URL=
5558
ENV WEBHOOK_GLOBAL_ENABLED=false
5659

src/config/env.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ export type Redis = {
6161
PREFIX_KEY: string;
6262
};
6363

64+
export type Rabbitmq = {
65+
ENABLED: boolean;
66+
URI: string;
67+
};
68+
6469
export type EventsWebhook = {
6570
APPLICATION_STARTUP: boolean;
6671
QRCODE_UPDATED: boolean;
@@ -116,6 +121,7 @@ export interface Env {
116121
CLEAN_STORE: CleanStoreConf;
117122
DATABASE: Database;
118123
REDIS: Redis;
124+
RABBITMQ: Rabbitmq;
119125
LOG: Log;
120126
DEL_INSTANCE: DelInstance;
121127
WEBHOOK: Webhook;
@@ -201,6 +207,10 @@ export class ConfigService {
201207
URI: process.env.REDIS_URI,
202208
PREFIX_KEY: process.env.REDIS_PREFIX_KEY,
203209
},
210+
RABBITMQ: {
211+
ENABLED: process.env?.RABBITMQ_ENABLED === 'true',
212+
URI: process.env.RABBITMQ_URI,
213+
},
204214
LOG: {
205215
LEVEL: process.env?.LOG_LEVEL.split(',') as LogLevel[],
206216
COLOR: process.env?.LOG_COLOR === 'true',

src/dev-env.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ REDIS:
7979
URI: "redis://localhost:6379"
8080
PREFIX_KEY: "evolution"
8181

82+
RABBITMQ:
83+
ENABLED: false
84+
URI: "amqp://guest:guest@localhost:5672"
85+
8286
# Global Webhook Settings
8387
# Each instance's Webhook URL and events will be requested at the time it is created
8488
WEBHOOK:

src/libs/amqp.server.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as amqp from 'amqplib/callback_api';
22

3+
import { configService, Rabbitmq } from '../config/env.config';
34
import { Logger } from '../config/logger.config';
45

56
const logger = new Logger('AMQP');
@@ -8,7 +9,8 @@ let amqpChannel: amqp.Channel | null = null;
89

910
export const initAMQP = () => {
1011
return new Promise<void>((resolve, reject) => {
11-
amqp.connect('amqp://admin:admin@localhost:5672', (error, connection) => {
12+
const uri = configService.get<Rabbitmq>('RABBITMQ').URI;
13+
amqp.connect(uri, (error, connection) => {
1214
if (error) {
1315
reject(error);
1416
return;
@@ -25,7 +27,7 @@ export const initAMQP = () => {
2527
channel.assertExchange(exchangeName, 'topic', { durable: false });
2628
amqpChannel = channel;
2729

28-
logger.log('Serviço do RabbitMQ inicializado com sucesso.');
30+
logger.log('AMQP initialized');
2931
resolve();
3032
});
3133
});

0 commit comments

Comments
 (0)