morganics edited this page Oct 24, 2018 · 4 revisions


This project also contains a managed MQTT client. The client has some additional functionality in comparison with the regular MqttClient. Those functionalities are reflecting the most common use cases and thus the ManagedClient provides a out-of-the-box MQTT client with the following features.

  1. The managed client is started once and will maintain the connection automatically including reconnecting etc.
  2. All MQTT application messages are added to an internal queue and processed once the server is available.
  3. All MQTT application messages can be stored to support sending them after a restart of the application
  4. All subscriptions are managed across server connections. There is no need to subscribe manually after the connection with the server is lost.

The managed Client is available as a separate nuget package (

The following code shows how to setup and start a managed MQTT client.

// Setup and start a managed MQTT client.
var options = new ManagedMqttClientOptionsBuilder()
    .WithClientOptions(new MqttClientOptionsBuilder()

var mqttClient = new MqttFactory().CreateManagedMqttClient();
await mqttClient.SubscribeAsync(new TopicFilterBuilder().WithTopic("my/topic").Build());
await mqttClient.StartAsync(options);

// StartAsync returns immediately, as it starts a new thread using Task.Run, 
// and so the calling thread needs to wait.

Message processing

Similar to the regular client the managed client also has a Publish method. But for the managed client this method will not throw an exception on failure because the message is only added to an internal queue and processed later.

But the managed client has several events which allows dealing with send errors etc.

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.