done implementing rabbit + need to fix delay bug
This commit is contained in:
parent
f1d02aadc0
commit
8bc7e1d8a0
3 changed files with 9 additions and 10 deletions
|
@ -6,18 +6,13 @@ export class NotificationService {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.rabbitmq = new RabbitMQ();
|
this.rabbitmq = new RabbitMQ();
|
||||||
this.rabbitmq.connect().then(() => {
|
this.startListener();
|
||||||
console.log('RabbitMQ connected');
|
|
||||||
}).catch((error) => {
|
|
||||||
console.error('Error connecting to RabbitMQ:', error);
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
startListener() {
|
async startListener() {
|
||||||
|
await this.rabbitmq.connect();
|
||||||
this.rabbitmq.startConsumer();
|
this.rabbitmq.startConsumer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const notificationService = new NotificationService();
|
const notificationService = new NotificationService();
|
||||||
notificationService.startListener();
|
|
|
@ -44,6 +44,10 @@ export class RabbitMQ {
|
||||||
|
|
||||||
async startConsumer() {
|
async startConsumer() {
|
||||||
try {
|
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);
|
await this.channel.prefetch(1);
|
||||||
console.log('Consumer started, waiting for messages...');
|
console.log('Consumer started, waiting for messages...');
|
||||||
this.channel.consume(this.queueName, async (message) => {
|
this.channel.consume(this.queueName, async (message) => {
|
||||||
|
|
|
@ -7,7 +7,7 @@ POST http://localhost:3000/todo
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
|
|
||||||
{
|
{
|
||||||
"title": "Go to the gym",
|
"title": "Go to the gymNEW!!!",
|
||||||
"description": "Go to the gym at 8pm",
|
"description": "Go to the gym at 8pm",
|
||||||
"due_date": "2023-07-08 12:00:00"
|
"due_date": "2023-07-08 12:00:00"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue