Getting Started with MQTT (1) - Brief Introduction

MQTT (MQ Telemetry Transport) message queue telemetry transport protocol

is a lightweight message protocol based on the TCP/IP protocol, based on the publish/subscribe Subscribe mode, machine-to-machine (M2M) communication, and binary transmission. Developed by IBM in 1999, it was opened to the public for free in 2010, and officially became the official standard of OASIS in 2014.

Although it has MQ in the name, it is not a Message Queue and it does not guarantee the order of messages.

Compared with RabbitMQ: Consider running on low bandwidth, unreliable 4G/LTE network (reliability), mostly used for IoT, M2M, IM.
Compared with HTTP: reduced traffic (low bandwidth), reduced device power consumption (low power consumption), support for message push, Pub/Sub model, bidirectional 1-to-many/many-to-many communication, etc.

The minimum packet size of MQTT is only a 2-byte header.



At present, Baidu, Ali, Tencent, JD.com, and China Mobile all have IoT platforms, and MQTT is a very important role in the IoT.

In the IoT environment, a large number of devices or sensors need to periodically send small data and receive external data. Such data exchanges exist in abundance.



MQTT forwards messages through Broker, so it can penetrate NAT, and similar protocols include AMQP, XMPP, etc.

The MQTT protocol is designed as the device is always online, and the data is stored in the memory, so MQTT is more memory-intensive.

Official website: http://mqtt.org/
Default port: 1883/8883 (TLS)
Latest standard: MQTT v3.1.1 (OASIS)
  English version: http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/mqtt-v3.1.1.html
  Chinese version: https://github.com/mcxiaoke/mqttNext

version MQTT v5. 0 will also be released soon. (No MQTT v4.0 because protocol level v3.1 is 3 and v3.1.1 is 4)
https://blog.codecentric.de/en/2017/11/hello-mqtt-version-5-0/

( 1) Basic concepts
Publish/Subscribe
replaces the traditional client/server model
Multi- dimensional decoupling
   Space decoupling: publishers and subscribers do not need to know each other’s
   time Decoupling: publishers and subscribers do not need to run at the same time (offline message)
   synchronization Decoupling: both publishing and receiving are asynchronous communication, no need to stop any processing
Subscribers can unsubscribe
Messages
Topics
tree structure named with "/", similar to REST, such as: home/light/brightness
wildcard:
   + single-layer wildcard such as , a/b/+" matches "a/b/c1" and "a/b/c2", but not "a/b/c/d"
   # Multiple wildcards such as "a/b/c/#" Can match "a/b/c", "a/b/c/d" and "a/b/c/d/e"
Naming convention: http://tinkerman.cat/mqtt-topic-naming-convention/
Server/Broker
is responsible for receiving messages, filtering messages and forwarding them to message subscribers. Clients other than
Client
Broker are clients that can publish or subscribe messages

* ** The pub/sub model is a topic-based message forwarding system. Each message will be posted on a specific topic. The
message will not be sent directly to the subscriber, but the publisher will first send the message with the topic to the broker.
Subscribers can subscribe to their own related topics from the broker. When the broker receives the published messages, the
broker starts to perform topic-based filtering and forwards specific messages to specific subscribers.

(2) Three roles Publisher Publisher -> Agent Broker
-> Subscriber Subscriber ( 3 )

14 message types )   at most once: sent once, no reply is required, the message may be lost. (Sensor data)   At least once: The sender did not receive the PUBACK from the receiver, it will be resent after a while, and the message may be repeated.











  Only once: The sending process goes through PUBREC, PUBREL, PUBCOMP to ensure that a packet is received only
once Retained Messages
Persistent Session
Last will & Testament
SYS topic
  Subscribe to topics located under the $SYS level to view server status information

( 6) Message filtering
Topic-based: Subscribing to topics of interest Topic-
based: Subscribing to filtering and querying messages of interest Type-
based : Filtering based on the type of messages

(7) The related software
MQTT is just a protocol standard, and the actual application also requires various software to achieve.

a - Servers/Brokers
VerneMQ https://vernemq.com/
EMQTT http://emqtt.io/
Mosquitto https://mosquitto.org/
Others: https://github.com/mqtt/mqtt.github.io/ wiki/servers

b - Client Library
Eclipse Paho https://www.eclipse.org/paho/
MQTT.js https://github.com/mqttjs/MQTT.js For

more information, please refer to: http://mqtt.org /software

(8) The difference between MQTT and message queue
  MQTT comes from an IBM product called MQSeries and has nothing to do with MQ.
  The message queue stores messages until they are consumed
  . There is only one consumer in the message queue that processes messages, and each subscriber who subscribes to a topic in MQTT will receive messages. The
  message queue must be created in advance and explicitly, and can be created in real time at any time in MQTT

(9) MQTT The difference with

HTTPhttp ://www.rfwireless-world.com/Terminology/MQTT-vs-HTTP.html

(10) Development module IoT boards
ESP8266 (Wifi chip), Arduino, Raspberry Pi (Raspberry Pi), LattePanda ( Latte Panda)

recommends reading two series of articles on MQTT in the HiveMQ Blog:
MQTT Essentials : https://www.hivemq.com/blog/mqtt-essentials/

MQTT Security Fundamentals : https://www.hivemq.com /blog/mqtt-security-fundamentals/


Reference:
https://www.hivemq.com/blog/how-to-get-started-with-mqtt
https://dzone.com/refcardz/getting-started-with- mqtt
http://geek.csdn.net/news/detail/228329
http://geek.csdn.net/news/detail/229509
http://dataguild.org/?tag=mqtt
http://www.blogjava.net/yongboy/category/54835.html
https://codezine.jp/article/corner/508
https://www.programmableweb.com/api-university/how-and-why-to-provide-event-driven-streaming-apis
https://www.survivingwithandroid.com/2016/10/mqtt-protocol-tutorial.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326179156&siteId=291194637