postwait / node-amqp

[UNMAINTAINED] node-amqp is an AMQP client for nodejs
MIT License
1.7k stars 357 forks source link

How to reject on acknowledge using messageObject callback argument #463

Closed JimmyPruitt closed 6 years ago

JimmyPruitt commented 6 years ago

How can I requeue an acknowledged message using the 4th argument in a queue's subscribe callback? i.e.,

q.subscribe({ack: true}, (message, headers, info, messageObject) => {
    messageObject.acknowledge(true) // I want to requeue when I acknowledge(true) here
})

acknowledge doesn't appear to accept a second argument like queue.shift, so messageObject.acknowledge(true, true) doesn't work. Adding requeue: true to the subscription options doesn't work either:

q.subscribe({ack: true, requeue: true}, (message, headers, info, messageObject) => {
    messageObject.acknowledge(true)
})

The documentation says not to call shift explicitly, so is there another way to accomplish this?

Thanks.

JimmyPruitt commented 6 years ago

I figured it out. The messageObject also has a function called reject, to be used instead:

q.subscribe({ack: true}, (message, headers, info, messageObject) => {
    messageObject.reject(true) // Will put the message back into the queue
})