Skip to content

Commit

Permalink
refactor: replace var env in message broker
Browse files Browse the repository at this point in the history
  • Loading branch information
Murzbul committed Feb 24, 2024
1 parent b5a2f75 commit 95203a4
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 35 deletions.
6 changes: 1 addition & 5 deletions .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions config/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
6 changes: 1 addition & 5 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
6 changes: 1 addition & 5 deletions src/Config/MainConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
6 changes: 1 addition & 5 deletions src/Config/validateEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion src/Shared/Infrastructure/RabbitMQMessageBroker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ void (async() =>
closedApplication({
server,
cache,
createConnection,
eventHandler,
createConnection,
messageBroker
});
}
Expand Down
8 changes: 0 additions & 8 deletions src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() =>
{
Expand All @@ -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>('IMessageBroker');
await messageBroker.connect(config.messageBroker);
Expand Down

0 comments on commit 95203a4

Please sign in to comment.