postwait / node-amqp

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

Best Practice for rejecting message after X attempts to process? #299

Open apveitas opened 10 years ago

apveitas commented 10 years ago

Hi Folks,

Am looking for some guidance on "best practice" as to how to tag a message on the consumer side with a property that keeps track of how many delivery attempts there have been. Let's call it "numDeliveryAttempts". This property would be incremented and checked to see if it reached a threshold to finally reject it (and have rabbitmq place in a DLQ).

conceptually, this is what we are desiring:

q.subscribe({ack: true}, function(data,headers,deliveryInfo,message) {

   messageHandler(data, function(err) {
        if (err != null) {
               if (deliveryInfo.redelivered) {
                    headers.numDeliveryAttempts++;
                } else {
                    console.log('FIRST TIME!!');
                    headers.numDeliveryAttempts = 1;
                }
                 if (headers.numDeliveryAttempts >= MAX_ATTEMPTS {
                      q.shift(true,false);
                 } else {
                      q.shift();
                 }
         }
        });
    });

Any advice much appreciated. Thanks in advance.

Al

podviaznikov commented 10 years ago

I have the same question.

Is it possible to update message headers? I want to update them in case of failure (before messageObject.reject(true);).

mcasimir commented 8 years ago

big +1