One possible solution is to hash the message using some sort of hash function you define, then check a cache object for that hash. If it is there, add one to the cache up to the configurable max, and if it's not there, set it to 1. Here's a quick and dirty prototype for you (note that the mcache
object should be in scope for all subscribers):
var mcache = {}, maxRetries = 3;
q.subscribe({ack: true}, function(data,headers,deliveryInfo,message) {
var messagehash = hash(message);
if(mcache[messagehash] === undefined){
mcache[messagehash] = 0;
}
if(mcache[messagehash] > maxRetries) {
q.shift(true,false); //reject true, requeue false (discard message)
delete mcache[messagehash]; //don't leak memory
} else {
try{
doSomething(data);
q.shift(false); //reject false
delete mcache[messagehash]; //don't leak memory
} catch(e) {
mcache[messagehash]++;
q.shift(true,true); //reject true, requeue true
}
}
}
if the message has a GUID, you can simply return that in the hash function.