<div dir="ltr">We use node-amqp to prefetch multiple messages and then ack them one at a time. It looks a bit like this:<div><br></div><div><pre class="" style="word-wrap:break-word;width:744.1666259765625px;margin-top:0px;margin-bottom:0px;padding:0px">
<div class="" id="file-queue-js-LC1" style="color:rgb(0,0,0);font-family:Consolas,'Liberation Mono',Courier,monospace;font-size:11.666666030883789px;line-height:13.333333015441895px"><br></div><div class="" id="file-queue-js-LC17">
<span class=""><font color="#000000" face="Consolas, Liberation Mono, Courier, monospace"><span style="line-height:13.328125px">function subscribe(queue) {
queue.bind('ingestion', '#');
var options = { ack : true, prefetchCount : 1000 };
queue.subscribe(options, function (payload, headers, deliveryInfo, message) {
importer.log(payload, function (err) {
try {
if (err) message.reject(true); // requeue the message
else message.acknowledge(false); // acknowledge only this message
} catch (e) {
logger.error('Error acknowledging queue message', { err : e });
}
});
});
}</span><span style="font-size:11.666666030883789px;line-height:13.333333015441895px"><br></span></font></span></div><div class="" id="file-queue-js-LC17"><span class=""><font color="#000000" face="Consolas, Liberation Mono, Courier, monospace"><span style="line-height:13.328125px"><br>
</span></font></span></div><div class="" id="file-queue-js-LC17" style><font face="arial, helvetica, sans-serif">Cheers,</font></div><div class="" id="file-queue-js-LC17" style><font face="arial, helvetica, sans-serif">-Calvin</font></div>
<div class="" id="file-queue-js-LC17" style><br></div><div class="" id="file-queue-js-LC17" style="color:rgb(0,0,0);font-family:Consolas,'Liberation Mono',Courier,monospace;font-size:11.666666030883789px;line-height:13.333333015441895px">
<span class=""><br></span></div></pre></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, May 6, 2013 at 2:09 AM, Matthias Radestock <span dir="ltr"><<a href="mailto:matthias@rabbitmq.com" target="_blank">matthias@rabbitmq.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On 05/05/13 23:48, <a href="mailto:macmillan.josh09@gmail.com" target="_blank">macmillan.josh09@gmail.com</a> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
My Node.js worker crashes (RECONDITION_FAILED - unknown delivery tag) if<br>
the following 2 conditions are met:<br>
<br>
1. I start it AFTER the queue have at least 2 messages.<br>
2. The q.shift() is in an async code.<br>
<br>
<a href="http://pastebin.com/uMQJn0Fe" target="_blank">http://pastebin.com/uMQJn0Fe</a><br>
</blockquote>
<br></div>
Looking at the amqp.js code, q.shift() acknowledges the last message that was received. So with your code...<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
q.subscribe({ack:true, prefetchCount: 0}, function (message,<br>
headers, deliveryInfo) {<br>
console.log(message);<br>
setTimeout(function() { q.shift(); }, 100);<br>
});<br>
});<br>
</blockquote>
<br></div>
due to the delayed execution, when two messages arrive in quick succession then the first to arrive won't be acknowledged at all and the second will be acknowledged twice. Rabbit is complaining about the latter.<br>
<br>
I've never used node-amqp, so I don't know what the correct approach is for accomplishing what you want to do. You may want to ask the node-amqp developers.<br>
<br>
Matthias<br>
<br>
______________________________<u></u>_________________<br>
rabbitmq-discuss mailing list<br>
<a href="mailto:rabbitmq-discuss@lists.rabbitmq.com" target="_blank">rabbitmq-discuss@lists.<u></u>rabbitmq.com</a><br>
<a href="https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss" target="_blank">https://lists.rabbitmq.com/<u></u>cgi-bin/mailman/listinfo/<u></u>rabbitmq-discuss</a><br>
</blockquote></div><br></div>