Search code examples
c#mqttmqttnet

Mqttnet managedMqttClient processed vs received Application message


I recently tried implementing a mqttclient in c# using the mqttnet package. I realized, that there are three events which can be invoked by the library:

ApplicationMessageProcessedAsync
ApplicationMessageReceivedAsync
ApplicationMessageSkippedAsync

While the last two are rather self-explanatory, I struggle to understand in what regard the ApplicationMessage is processed after its reception. Hence the question: why does ApplicationMessageProcessedAsync exist. Also, under what circumstances might the client decide to skip an ApplicationMessage und could this also be related to the processing of a message?

I would be happy for any help, as documentation in the MqttNet package is rather non-existent.

thanks J


Solution

  • You confuse receiving and sending here. While ApplicationMessageReceivedAsync is called when a message is received from the broker, the other two relate to publishing messages.

    The MqttNet ManagedClient internally has a queue, from which it actually publishes messages. If you call EnqueueAsync(message), but your queue is allready full, the ApplicationMessageSkippedAsync event gets called, to tell you about the queue overflow. The message is then not sent.

    On the other hand ApplicationMessageProcessedAsync is called when a message is published. Depending on QoS level, this is called at slightly different times. This event is also called, when publishing a message fails. In that case it contains the exception for more information.