|
|
Posted on 2/15/2019 1:22:03 PM
|
|
|
|

1 What is MQTT?
MQTT (Message Queuing Telemetry Transport) is an instant messaging protocol developed by IBM that has the potential to become an important part of the Internet of Things. MQTT, a messaging protocol based on the publish/subscribe programming pattern of binary messages, is now an OASIS specification and is ideal for IoT scenarios that require low power consumption and limited network bandwidth due to its simplicity.
2 MQTTnet
MQTTnet is a high-performance .NET open-source library based on MQTT communication, which supports both MQTT server-side and client-side. And the author is also kept updated, and currently supports the new version of . NET core, which is why MQTTnet was chosen. MQTTnet is not the most downloaded MQTT open source library for .NET on Github, but also MqttDotNet, nMQTT, M2MQTT, etc
The MQTT server used in this article is emqx, and you need to understand the following knowledge when using MQTTnet to communicate with emqx:
MQTTnet Document Address:The hyperlink login is visible. EMQX Document Address:The hyperlink login is visible.
First, create a new .NET Core console project with vs and install MQTTnet using the nuget command, as follows:
First of all, the renderings:
(MQTTnet disconnection and reconnection mechanism)
(Offline message received by MQTTnet)
(EMQX Statistics)
(EMQX Session Statistics)
(EMQX Cache Message Statistics) Keep message definitions
If the RELEASE tag bit of a PUBLISH message is set to 1, the message is called a "retained message";
Broker's handling of retention messages
The broker stores the last retained message for each topic and its QosWhen the client subscribed to the topic goes live, the broker needs to deliver the message to it.
MQTT holds the deletion of messages
Method 1: Send a retained message with an empty message body; Method 2: Send the latest reserved message to overwrite the previous one;
Finally, attach the source code:
(End)
|
Previous:jQuery study notesNext:Read books, learn, fitness, make money, and love someone with your heart
|