From 95203a49bcee7171a9c58c5534221367adbc4507 Mon Sep 17 00:00:00 2001 From: nrusso Date: Sat, 24 Feb 2024 13:09:36 -0300 Subject: [PATCH] refactor: replace var env in message broker --- .env.dev | 6 +----- config/custom-environment-variables.json | 6 +----- config/default.json | 6 +----- src/Config/MainConfig.ts | 6 +----- src/Config/validateEnv.ts | 6 +----- src/Shared/Infrastructure/RabbitMQMessageBroker.ts | 2 +- src/index.ts | 2 +- src/worker.ts | 8 -------- 8 files changed, 7 insertions(+), 35 deletions(-) diff --git a/.env.dev b/.env.dev index a7fd4e8c..369773f9 100644 --- a/.env.dev +++ b/.env.dev @@ -30,11 +30,7 @@ CACHE_USER=experience CACHE_PASSWORD=ewsua132435 CACHE_ENABLE=false -MESSAGE_BROKER_PROTOCOL=amqp -MESSAGE_BROKER_HOST=rabbitmq -MESSAGE_BROKER_PORT=5672 -MESSAGE_BROKER_USER=user -MESSAGE_BROKER_PASSWORD=password +MESSAGE_BROKER_URI=amqps://experience:experience@rabbitmq/experience # MinIO config MINIO_HOST=minio diff --git a/config/custom-environment-variables.json b/config/custom-environment-variables.json index 9193f0a4..cb620d9b 100644 --- a/config/custom-environment-variables.json +++ b/config/custom-environment-variables.json @@ -38,11 +38,7 @@ "enable": "CACHE_ENABLE" }, "messageBroker": { - "protocol": "MESSAGE_BROKER_PROTOCOL", - "hostname": "MESSAGE_BROKER_HOST", - "port": "MESSAGE_BROKER_PORT", - "username": "MESSAGE_BROKER_USER", - "password": "MESSAGE_BROKER_PASSWORD" + "uri": "MESSAGE_BROKER_URI" }, "filesystem": { "minio": { diff --git a/config/default.json b/config/default.json index a1525b50..0dde4af0 100644 --- a/config/default.json +++ b/config/default.json @@ -38,11 +38,7 @@ "enable": true }, "messageBroker": { - "protocol": "amqp", - "hostname": "rabbitmq", - "port": 5672, - "username": "user", - "password": "password" + "uri": "amqps://user:password@rabbitmq/user" }, "filesystem": { "minio": { diff --git a/src/Config/MainConfig.ts b/src/Config/MainConfig.ts index ae2f4257..70f4b8cb 100644 --- a/src/Config/MainConfig.ts +++ b/src/Config/MainConfig.ts @@ -95,11 +95,7 @@ export type ValidateSettingsType = { }; export type MessageBrokerConfig = { - protocol: string, - hostname: string, - username: string, - password: string, - port: number + uri: string } export type ConfigType = { diff --git a/src/Config/validateEnv.ts b/src/Config/validateEnv.ts index 1d3789ed..e72e6518 100644 --- a/src/Config/validateEnv.ts +++ b/src/Config/validateEnv.ts @@ -24,11 +24,7 @@ export function validateEnv() CACHE_PASSWORD: str({ default: '12345678' }), CACHE_ENABLE: bool({ default: false }), - MESSAGE_BROKER_PROTOCOL: str(), - MESSAGE_BROKER_HOST: str(), - MESSAGE_BROKER_PORT: port(), - MESSAGE_BROKER_USER: str(), - MESSAGE_BROKER_PASSWORD: str(), + MESSAGE_BROKER_URI: str(), DB_URI: str(), DB_ORM_DEFAULT: str(), diff --git a/src/Shared/Infrastructure/RabbitMQMessageBroker.ts b/src/Shared/Infrastructure/RabbitMQMessageBroker.ts index 5c2befd6..53531e72 100644 --- a/src/Shared/Infrastructure/RabbitMQMessageBroker.ts +++ b/src/Shared/Infrastructure/RabbitMQMessageBroker.ts @@ -13,7 +13,7 @@ class RabbitMQMessageBroker implements IMessageBroker { if (!this.#connection) { - this.#connection = await connect(config); + this.#connection = await connect(config.uri); this.#channel = await this.#connection.createChannel(); } } diff --git a/src/index.ts b/src/index.ts index 233d2711..5c391ae6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -70,8 +70,8 @@ void (async() => closedApplication({ server, cache, - createConnection, eventHandler, + createConnection, messageBroker }); } diff --git a/src/worker.ts b/src/worker.ts index a974f8aa..9407ff77 100644 --- a/src/worker.ts +++ b/src/worker.ts @@ -13,9 +13,6 @@ import ICacheDataAccess from './Main/Infrastructure/Repositories/ICacheDataAcces import { IMessageBroker } from './Shared/Infrastructure/IMessageBroker'; import MainConfig from './Config/MainConfig'; import NotificationEmailJob from './Notification/Infrastructure/Jobs/NotificationEmailJob'; -import { EventHandler } from '@digichanges/shared-experience'; -import EmailEvent from './Auth/Infrastructure/Events/EmailEvent'; -import SendMessageEvent from './Notification/Domain/Events/SendMessageEvent'; void (async() => { @@ -30,11 +27,6 @@ void (async() => await createConnection.initConfig(); await createConnection.create(); - // Set EventHandler and all events - const eventHandler = EventHandler.getInstance(); - eventHandler.setEvent(new EmailEvent()); - eventHandler.setEvent(new SendMessageEvent()); - // Message Broker const messageBroker = DependencyInjector.inject('IMessageBroker'); await messageBroker.connect(config.messageBroker);