From 6e343841296631aca407dfbd7abcb72e17abe656 Mon Sep 17 00:00:00 2001 From: Kfir Dayan Date: Thu, 13 Jul 2023 11:01:02 +0300 Subject: [PATCH] beautifying --- notification-service/src/main.ts | 3 +- notification-service/src/rabbitmq/RabbitMQ.ts | 29 ++++--------------- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/notification-service/src/main.ts b/notification-service/src/main.ts index 0237fae..5db0e27 100644 --- a/notification-service/src/main.ts +++ b/notification-service/src/main.ts @@ -12,6 +12,7 @@ export class NotificationService { this.currentDate = DateService.getInstance(); this.rabbitmq = new RabbitMQ(); this.mongoModel = new MongoDbModel(); + this.startListener(); } @@ -45,5 +46,3 @@ export class NotificationService { console.log("Sending notification for Todo:", todo._id); } } - -const notificationService = new NotificationService(); diff --git a/notification-service/src/rabbitmq/RabbitMQ.ts b/notification-service/src/rabbitmq/RabbitMQ.ts index 46011f5..aad0395 100644 --- a/notification-service/src/rabbitmq/RabbitMQ.ts +++ b/notification-service/src/rabbitmq/RabbitMQ.ts @@ -13,7 +13,7 @@ export class RabbitMQ { constructor() { this.envService = EnvService.getInstance(); - this.queueName = this.envService.getEnvVariable('RABBITMQ_QUEUE_NAME'); + this.queueName = this.envService.getEnvVariable("RABBITMQ_QUEUE_NAME"); this.mongoClient = new MongoDbModel(); @@ -30,10 +30,10 @@ export class RabbitMQ { try { const connection = await amqp.connect({ protocol: "amqp", - hostname: this.envService.getEnvVariable('RABBITMQ_HOST'), - port: parseInt(this.envService.getEnvVariable('RABBITMQ_PORT')), - username: this.envService.getEnvVariable('RABBITMQ_USERNAME'), - password: this.envService.getEnvVariable('RABBITMQ_PASSWORD'), + hostname: this.envService.getEnvVariable("RABBITMQ_HOST"), + port: parseInt(this.envService.getEnvVariable("RABBITMQ_PORT")), + username: this.envService.getEnvVariable("RABBITMQ_USERNAME"), + password: this.envService.getEnvVariable("RABBITMQ_PASSWORD"), }); this.channel = await connection.createChannel(); @@ -44,25 +44,6 @@ export class RabbitMQ { } } - async create(payload: ITodo, delayTimeForQueue: number) { - const message = JSON.stringify({ payload, delayTimeForQueue }); - const options = { - persistent: true, - expiration: delayTimeForQueue.toString(), - }; - - try { - await this.channel.sendToQueue( - this.queueName, - Buffer.from(message), - options - ); - } catch (error) { - console.error("Error sending message to RabbitMQ:", error); - throw error; - } - } - async startConsumer(callback: Function): Promise { this.channel.assertQueue(this.queueName); this.channel.consume(this.queueName, (message: ConsumeMessage | null) => {