done implementing rabbit + need to fix delay bug

This commit is contained in:
Kfir Dayan 2023-07-08 11:39:54 +03:00
parent f1d02aadc0
commit 8bc7e1d8a0
3 changed files with 9 additions and 10 deletions

View file

@ -6,18 +6,13 @@ export class NotificationService {
constructor() {
this.rabbitmq = new RabbitMQ();
this.rabbitmq.connect().then(() => {
console.log('RabbitMQ connected');
}).catch((error) => {
console.error('Error connecting to RabbitMQ:', error);
});
this.startListener();
}
startListener() {
async startListener() {
await this.rabbitmq.connect();
this.rabbitmq.startConsumer();
}
}
const notificationService = new NotificationService();
notificationService.startListener();
const notificationService = new NotificationService();

View file

@ -44,6 +44,10 @@ export class RabbitMQ {
async startConsumer() {
try {
if (!this.channel) {
throw new Error('Channel is not initialized. Make sure to call connect before starting the consumer.');
}
await this.channel.prefetch(1);
console.log('Consumer started, waiting for messages...');
this.channel.consume(this.queueName, async (message) => {

View file

@ -7,7 +7,7 @@ POST http://localhost:3000/todo
Content-Type: application/json
{
"title": "Go to the gym",
"title": "Go to the gymNEW!!!",
"description": "Go to the gym at 8pm",
"due_date": "2023-07-08 12:00:00"
}