test rabbit

This commit is contained in:
AdisakKanthawilang 2024-11-25 11:27:30 +07:00
parent 6f1e2339f5
commit e47d3a88ef

View file

@ -25,9 +25,11 @@ export async function init() {
console.log(channel ? "[AMQ] Create channel success" : "[AMQ] Create channel failed"); console.log(channel ? "[AMQ] Create channel success" : "[AMQ] Create channel failed");
channel.assertQueue(queue, { durable: true }); //----> (1.5) assert queue and set durable (if "true" save to disk on RabbitMQ) await Promise.all([
channel.assertQueue(queue_org, { durable: true }); channel.assertQueue(queue, { durable: true }), //----> (1.5) assert queue and set durable (if "true" save to disk on RabbitMQ)
channel.prefetch(1); channel.assertQueue(queue_org, { durable: true }),
channel.prefetch(1)
]);
sendToQueue = (payload: any, persistent = true) => { sendToQueue = (payload: any, persistent = true) => {
//----> (2) sendQueue To RabbitMQ and set persistent (if "true" redo the failed queue when server run again) //----> (2) sendQueue To RabbitMQ and set persistent (if "true" redo the failed queue when server run again)
@ -41,10 +43,11 @@ export async function init() {
}; };
console.log("[AMQ] Listening for message..."); console.log("[AMQ] Listening for message...");
await Promise.all([
await createConsumer(queue, channel, handler); //----> (3) Process Consumer createConsumer(queue, channel, handler), //----> (3) Process Consumer
await createConsumer(queue_org, channel, handler_org); createConsumer(queue_org, channel, handler_org)
// createConsumer(queue2, channel, handler2); // createConsumer(queue2, channel, handler2);
]);
} }
let retries = 0; let retries = 0;