My M2Mqtt open source library has finally come to version 3.0 with two important news !

In the first place, the operations of publish, subscribe and unsubscribe have become completely asynchronous. Until the previous version , the corresponding methods were synchronous even if the library raised related events on published message and subscription / unsubscription occurred. In particular , in the Publish() method the exchange of messages with the broker was run  to ensure the required QoS ( PUBACK for QoS 1 , PUBREC , PUBREL and PUBCOMP for QoS2 ) while in the Subscribe() and Unsubscribe() methods handled the acknowledge ( SUBACK and UNSUBACK ). Now , these methods not bother to put a message in a queue and immediately return the message id itself , which is why there is a "breaking change" on the Subscribe() method that does not return the array with the "granted" QoS level. This array is still provided at the end of the asynchronous operation in the event args object of the corresponding event.

I talked about a queue? Yes! I added the management of inflight queue !

The concept of inflight queue is clearly present in the MQTT world and it is used to manage all messages relating to the operations of publish, subscribe and unsubscribe. The new version of the library has a dedicated thread that handles this queue , ensuring the asynchronous execution of these tasks and exchanging acknowledgment messages with the broker according to the desired QoS . Thanks to this queue , in the case of QoS Level 2 , the flow is resumed from the point where it was interrupted if the connection with the broker is closed (not still be handled the persistence of the queue).

A further change is the addition of a single thread to raise the events of the library (in the previous version was created a thread "on the fly" for each event ).

I hope I done something pleasing for all those who use this library .... and apparently there are a few !

As always, the library is available on CodePlex, Nuget and in the Microsoft Code Gallery !