In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces you how to understand the MQTT protocol and its principles. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
MQTT protocol
The full name of MQTT protocol is Message Queuing Telemetry Transport, which translates to message queue telemetry transmission protocol. It is a commonly used application layer protocol of the Internet of things. It runs in the application layer of TCP/IP and relies on TCP protocol, so it has very high reliability. At the same time, it is a lightweight protocol based on TCP protocol model to publish / subscribe topic messages, and it is also what we often call sending and receiving data. Let's take a preliminary look at the names and functions related to mqtt.
The biggest advantage of MQTT is that it can provide real-time and reliable message service for remote devices with very little code and limited bandwidth. As an instant messaging protocol with low overhead and low bandwidth consumption, MQTT is widely used in the Internet of things, small devices, mobile applications and so on.
Which layer of the protocol is MQTT?
As we all know, the TCP/IP reference model can be divided into four layers: application layer, transport layer, network layer and link layer. TCP and UDP are located in the transport layer, and the common protocols in the application layer are HTTP, FTP, SSH and so on. The MQTT protocol runs on TCP and belongs to the application layer protocol, so MQTT can be used wherever the TCP/IP protocol stack is supported.
MQTT communication model
MQTT protocol provides one-to-many message publishing, which can reduce the coupling of applications. Users only need to write a very small amount of application code to complete one-to-many message publishing and subscription. The protocol is based on model, and there are three main identities in the protocol: publisher (Publisher), server (Broker) and subscriber (Subscriber). Among them, the publishers and subscribers of MQTT messages are both clients, and the server, as a transit existence, forwards the messages published by the publishers to all subscribers who subscribe to the topic; the publishers can publish all topics within their authority, and the message publishers can be subscribers at the same time, realizing the decoupling of producers and consumers, and the published messages can be subscribed by multiple subscribers at the same time.
The schematic diagram of the MQTT communication model is as follows:
Functions of the mqtt001MQTT client:
Publish messages to other relevant clients.
The subscription topic requests to receive related application messages.
Unsubscribe to the topic request to remove the received application message.
Terminate the connection from the server.
MQTT client server features:
MQTT server is often called Broker (message broker). It is generally a cloud server. For example, some Internet of things platforms of the BTA Big three often use MQTT protocol, which is located between message publishers and subscribers so that they can be used to receive messages and send them to subscribers. Its functions include:
Accept network connection requests from the client.
Accept application messages issued by the client.
Handle client subscription and unsubscribe requests.
Forward application messages to eligible subscribed clients (including the publisher itself).
Message subject and quality of Service
What is the theme? The MQTT server adds a label for each connected client (subscriber), which matches all subscriptions in the server, and the server forwards the message to each client (subscriber) that matches the tag. Of course, subscribers also need permission to subscribe to the corresponding topic. For example, in Aliyun, subscribers can only subscribe to topics under the same product, not across products. This kind of processing can achieve the security of the information and multiple subscribers can receive the message in time. A topic can have multiple levels, separated by slash characters, such as / test and / test/test1/test2 are valid themes.
Publishers and subscribers can publish and subscribe to topics through the name of the topic, generally in the form of UTF-8 coding (you can't make a mistake with an English string anyway). For example, we can directly define a topic named "test". Most MQTT servers support dynamic publish / subscribe topics, that is, there is no topic in the current server, but the client can publish / subscribe messages to the topic directly. In this way, the server will create the corresponding topic, of course, the server will generally provide multiple system topics by default, all connected clients can subscribe.
After each client establishes a connection with the server, there is a session, and there is a stateful interaction between the client and the server. The subscription is based on the session, and each subscription contains a topic filter, which is an expression that identifies one or more topics related to the subscription. The topic filter can use wildcards, so subscribers need to specify the topic name and quality of service (QoS) of the subscription. Subscribers can subscribe to multiple topics and receive messages published by multiple publishers. Similarly, the publisher needs to first establish a session with the server and specify the topic name and quality of service to be sent, and it can also send messages to multiple different topics.
So what is the quality of service? MQTT offers three levels of quality of service:
QoS0: send a message at most. After the message is sent, the receiver will not send a response, and the sender will not resend the message. The message may be delivered once or not at all. This quality of service is often used in unimportant message delivery, because it doesn't matter if the message is lost.
QoS1: send a message at least once (messages need to be delivered at least once or multiple times). The variable header of QoS1's PUBLISH message contains a message identifier, which requires PUBACK message confirmation. That is, the receiver is required to return the PUBACK reply message.
QoS2: this is the highest level of quality of service, message loss and repetition are unacceptable, but there is an additional overhead to use this level of quality of service, which is often used in payments, because payments are necessary and only successful once, so you can't afford not to pay or pay multiple times.
On how to understand the MQTT protocol and protocol principles to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 299
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.