test rabbit

This commit is contained in:
AdisakKanthawilang 2024-11-18 10:28:08 +07:00
parent 376b50f729
commit 53c7bc7b62

View file

@ -43,7 +43,7 @@ export async function init() {
console.log("[AMQ] Listening for message...");
createConsumer(queue, channel, handler); //----> (3) Process Consumer
// createConsumer(queue_org, channel, handler_org);
createConsumer(queue_org, channel, handler_org);
// createConsumer(queue2, channel, handler2);
}
@ -58,17 +58,18 @@ function createConsumer( //----> consumer
queue,
async (msg) => {
if (!msg) return;
console.log("[AMQ] on on create consumer");
if ((await handler(msg)) || retries++ >= 3) {
retries = 0;
console.log("[AMQ] process consumer success");
return channel.ack(msg);
}
console.log("[AMQ] process consumer fail");
return await new Promise((resolve) => setTimeout(() => resolve(channel.nack(msg)), 3000));
},
{ noAck: false },
);
console.log(queue ? "[AMQ] create consumer success" : "[AMQ] create consumer failed");
}
async function handler(msg: amqp.ConsumeMessage): Promise<boolean> {