MQTTnet icon indicating copy to clipboard operation
MQTTnet copied to clipboard

How to prevent ack on message consume failure

Open colinmc86 opened this issue 4 years ago • 2 comments

Hello,

If I am consuming QOS 1 messages, and encounter an error consuming message, how can I prevent the message from being acked? If I have an uncaught exception inside of my client.UseApplicationMessageReceivedHandler handler will it redeliver ?

Thanks,

Colin

colinmc86 avatar Feb 23 '21 01:02 colinmc86

You can set MqttApplicationMessageReceivedEventArgs.ProcessingFailed to true. Then no ACK will be sent.

chkr1011 avatar Feb 23 '21 16:02 chkr1011

@chkr1011 Shouldn't that be the default when an exception is catched when QoS1 is requested?

So if you want QoS1 you need to do something like the following?

public async Task Handler(MqttApplicationMessageReceivedEventArgs arg)
{
    try
    {
        // Do your magic here
    }
    catch
    {
        arg.ProcessingFailed = true;
        throw;
    }
}

ramonsmits avatar Apr 04 '21 09:04 ramonsmits

I assume this question in properly answered.

chkr1011 avatar Oct 02 '22 09:10 chkr1011