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

@@ -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();
});
});