Rabbit Mq Publisher Nack behavior

48 views
Skip to first unread message

Pchase

unread,
Sep 9, 2020, 2:53:06 PM9/9/20
to rabbitmq-users
In this tutorial

in section:
Strategy #3: Handling Publisher Confirms Asynchronously

It has a nack for one item but cleans all items below the deliveryTag.  Is this the correct behavior?  I will only get a nack for one item but all items below it are essentially ack'd?

channel.BasicNacks += (sender, ea) => { 
   outstandingConfirms.TryGetValue(ea.DeliveryTag, out string body);
   cleanOutstandingConfirms(ea.DeliveryTag, ea.Multiple); 
};  


Luke Bakken

unread,
Sep 14, 2020, 12:56:34 PM9/14/20
to rabbitmq-users
Hello,

The ea instance has a Multiple field that indicates if the Nack is for every delivery tag up to the one in the object, or just the one.


Thanks,
Luke

Pchase

unread,
Sep 14, 2020, 3:55:08 PM9/14/20
to rabbitmq-users
The example shows it only tries to do something with the current deliveryTag.  Shouldn't the example show that it tries to do something with all the items below it instead of clearing them out?


var nacked = outstandingConfirms.Where(k => k.Key <= sequenceNumber);

foreach (var entry in nacked)
{
   outstandingConfirms.TryRemove(entry.Key, out x); 
   Console.WriteLine($"Message has been nack-ed. Sequence number: {entry.Key}, multiple: {ea.Multiple}");  
     

Luke Bakken

unread,
Sep 14, 2020, 4:56:44 PM9/14/20
to rabbitmq-users
Hello,

Please remember that this is example code. We have to strike a balance between understand-ability and completeness.

A real application would possibly re-try messages, raise exceptions, etc. We can't cover all use cases. Real applications would keep a sliding window of outstanding confirmations and throttle publishers if the window is full. Each outstanding confirm could have a deadline after which a decision should be made as to re-publishing, discarding or otherwise dealing with the missed confirmation.

In general if your application starts missing confirmations something is awry with your environment.

Thanks,
Luke
Reply all
Reply to author
Forward
0 new messages