This article is a mirror article of machine translation, please click here to jump to the original article.

View: 65648|Reply: 5

[Console Program] .net/c# Implement MQTT communication tutorial source code using MQTTnet

[Copy link]
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:

First acquaintance with the EMQX (EMQTTD) message queue
https://www.itsvse.com/thread-6965-1-1.html
(Source: Architect_Programmer)
Mqtt's service quality level Qos
https://www.itsvse.com/thread-6960-1-1.html
(Source: Architect_Programmer)
Several EMQTT knowledge points
https://www.itsvse.com/thread-6966-1-1.html
(Source: Architect_Programmer)

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 notes
Next:Read books, learn, fitness, make money, and love someone with your heart
 Landlord| Posted on 2/15/2019 1:27:47 PM |
If there are two identical clientIds, the latter will push the former off, because my program has a disconnection and reconnection mechanism, it will squeeze out each other's lines!


Posted on 2/15/2019 1:46:29 PM |
Come on, come on!
Posted on 10/24/2021 10:30:38 PM |
Look
Posted on 3/25/2022 2:05:15 PM |
Just need to take a look
Posted on 7/14/2022 1:55:19 PM |
Thanks for sharing! Learn to learn
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com