fix rabbit
This commit is contained in:
parent
b0dc1917c4
commit
76f5a9fe4d
1 changed files with 7 additions and 2 deletions
|
|
@ -43,6 +43,8 @@ export async function init() {
|
||||||
// createConsumer(queue2, channel, handler2);
|
// createConsumer(queue2, channel, handler2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let retries = 0;
|
||||||
|
|
||||||
function createConsumer( //----> consumer
|
function createConsumer( //----> consumer
|
||||||
queue: string,
|
queue: string,
|
||||||
channel: amqp.Channel,
|
channel: amqp.Channel,
|
||||||
|
|
@ -53,7 +55,10 @@ function createConsumer( //----> consumer
|
||||||
async (msg) => {
|
async (msg) => {
|
||||||
if (!msg) return;
|
if (!msg) return;
|
||||||
|
|
||||||
if (await handler(msg)) return channel.ack(msg);
|
if ((await handler(msg)) || retries++ >= 3) {
|
||||||
|
retries = 0;
|
||||||
|
return channel.ack(msg);
|
||||||
|
}
|
||||||
|
|
||||||
return await new Promise((resolve) => setTimeout(() => resolve(channel.nack(msg)), 3000));
|
return await new Promise((resolve) => setTimeout(() => resolve(channel.nack(msg)), 3000));
|
||||||
},
|
},
|
||||||
|
|
@ -162,6 +167,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue