MQTTnet
is a high performance .NET library for MQTT based communication.
This is GitHub Link. https://github.com/chkr1011/MQTTnet . It provides a MQTT client and a MQTT server (broker). The implementation is based on the documentation from http://mqtt.org/.
This is how I have created managed
MQTT client. Here is the link https://github.com/chkr1011/MQTTnet/wiki/ManagedClient
// Setup and start a managed MQTT client. var options = new ManagedMqttClientOptionsBuilder() .WithAutoReconnectDelay(TimeSpan.FromSeconds(5)) .WithClientOptions(new MqttClientOptionsBuilder() .WithClientId("Client1") .WithTcpServer("broker.hivemq.com") .WithTls().Build()) .Build(); this.mqttClient = new MqttFactory().CreateManagedMqttClient(new MqttNetLogger("IDMQTTManagedPublisher")); await this.mqttClient.SubscribeAsync(new TopicFilterBuilder().WithTopic("RequestTopic").Build()); SubscribeToApplicationMessageReceived(); await this.mqttClient.StartAsync(options);
Subscription to ApplicationMessageProcessed
event
private void SubscribeToApplicationMessageProcessed() { this.mqttClient.ApplicationMessageProcessed += (s, e) => { }; }
Message sending code
var messagePayload = new MqttApplicationMessageBuilder() .WithTopic("RequestTopic") .WithPayload(message) .WithExactlyOnceQoS() .WithRetainFlag() .Build(); await mqttClient.PublishAsync(messagePayload);
But ApplicationMessageProcessed
event is not firing in managed MQTTnet client