Skip to content
Christian edited this page Oct 26, 2024 · 16 revisions

How does MQTT work and what are the best practices?

This project does not cover explanation of MQTT as a such. This library only has barely comments so that knowledge about the protocol is required before getting started with this library.

This is by design and will not change. The recommended source for tutorials etc. is https://www.hivemq.com/blog/how-to-get-started-with-mqtt.

More detailed information is available in the officials RFCs of the MQTT protocol (v3.1.1, v5.0.0).

Which version should I use?

Only the latest version 4 and version 5 are supported. Version 3 and older are no longer supported.

The following table shows which version must be used.

Target Framework MQTTnet version
.NET 8.0 5
.NET 5.0 - 7.0 4
.NET Core 1.1+ 4
.NET Framework 4.5.2 - 4.8.1 4
.NET Standard 1.3 - 2.1 4
Blazor WebAssembly 5
Mono 5.2+ 4
UWP 10.0.10240+ 4
Xamarin (Android / iOS) 4

How to use this library?

Code samples for using this library are available in the repository located in the Samples directory.

Samples for version 5.x

Samples for version 4.x

Samples for version 3.x are no longer available!

Most of these samples can also be executed. This requires cloning this repository, compiling and running the console application MQTTnet.Samples.csproj.

How to debug the protocol?

For MQTT protocol debugging and analytics the MQTT Client mqttMultimeter should be used to inspect messages, payloads etc. It is recommended to test connections and features using this client before opening tickets.

The code of this library can be debugged via attaching the debugger to certain Unit Tests.

FAQ

I have performance issues.

In order to get maximum performance, it is very important to use a RELEASE build of the affected application. Also, the MQTTnet log should not be activated (off by default).

My connection remains "Connected" (IsConnected=true) but the socket is already disconnected, or the network connection is broken/disabled.

This is by design. See post https://github.com/xamarin/xamarin-android/issues/1347#issuecomment-369729481. So, switch over to at least QoS 1. Then the client can use a timeout and disconnect when no response is received.

I have troubles connecting when using TLS.

Please see https://docs.microsoft.com/en-us/dotnet/core/compatibility/cryptography/5.0/default-cipher-suites-for-tls-on-linux.