test rabbit
This commit is contained in:
parent
376b50f729
commit
53c7bc7b62
1 changed files with 5 additions and 4 deletions
|
|
@ -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> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue