feat: Added rabbitmq to send events

This commit is contained in:
Davidson Gomes
2023-08-02 17:39:07 -03:00
parent ab5289a136
commit 55f8e179af
5 changed files with 24 additions and 2 deletions

View File

@@ -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',

View File

@@ -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:

View File

@@ -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<void>((resolve, reject) => {
amqp.connect('amqp://admin:admin@localhost:5672', (error, connection) => {
const uri = configService.get<Rabbitmq>('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();
});
});