MQTT is based on the Publish/Subscribe mode for communication and data exchange, which is essentially different from the Request/Response mode of HTTP.
Subscriber will subscribe to a Topic to the Broker. After a successful subscription, the broker forwards the message under the topic to all subscribers.
Topic uses ‘/’ as a separator to distinguish between different levels. Topics containing the wildcard ‘+’ or ‘#’ are also called as Topic Filters, and topics without wildcards are called Topic Names. E.g:
sensor/1/temperature sensor/1/# sensor/+/temperature
MQTT broker, also known as the MQTT message server, can be a server or a cluster of servers running MQTT message server software. MQTT broker is responsible for receiving network connections from the client and handling the client's requests of Subscribe/Unsubscribe and Publish, as well as forwarding the messages published by the client to other subscribers.
MQTT broker is widely used in the industries of power, new energy, smart city, smart home, smart meter reading, vehicle networking, finance and payment, operators and so on.
mosquitto_subfor publishing and Subscribing. Mosquitto is lightweight and suitable for use on all devices from low-power single-board computers to servers.
Support multi-server node clustering and support automatic discovery of nodes. Compared to a single server, a cluster can bring the following advantages through collaboration between multiple servers:
The main usage scenarios of data persistence include recording the client's online and offline status, subscribed topic information, message content, and sending message receipts after the message arrives to various databases such as Redis, MySQL, PostgreSQL, MongoDB, and Cassandra.
HTTP message publishing interface support, which makes it easier for upper-layer applications to send messages to devices through the REST API;
MQTT broker bridging, that supports message bridging between different MQTT brokers or different clusters. Bridging makes it easy to bridge messages to cloud services, streaming services, or other MQTT message servers. Bridging can accomplish some functions that cannot be achieved by simply using a cluster, such as deploying across VPCs, supporting heterogeneous nodes, and increasing the service limit for a single application;
Support for shared subscriptions. Shared subscription is a mechanism that allows the distribution of messages for a subscription group to be evenly distributed to members of a subscription group. In a shared subscription, clients that subscribe to the same topic receive messages under this topic in turn. The same message will not be sent to multiple subscribing clients, thus achieving load balancing between multiple subscribing clients;
Rule engine support for configuring the processing and response rules of message streaming and device events. The rules describe three configurations of w**here the data comes from, how to filter and process the data , where the results go to.** One of the available rules contains three elements: trigger event ( Trigger when satisfying certain conditions, process rules (filtering and processing data from context information), response actions (such as persistence to database, republishing processed messages, forwarding messages to message queues, etc.).
To facilitate testing, we use the online broker provided by EMQ , which contains all the functions of EMQ X Enterprise.
Broker address： broker.emqx.io
Broker port： 1883、8883（SSL）、8083（Websocket）、8084（WSS）
We use the online version of the WebSocket tool provided by EMQ to connect to the client :http://tools.emqx.io。
Open the address http://tools.emqx.io using the browser, click the New Connection button in the lower left corner, and fill in the link information in the box on the right. Fill out the required fields and click the Connect button to create a link and connect to the Broker.
After the connection is successful, click Write a message in the lower right corner to pop up the message publishing box, fill out Topic and Payload and click the send icon to publish the message.
Subscribe to regular topics
In the Subscriptions module, subscribe to the hello topic. At this point, if you send a message to the hello topic, the message will be received in the message list (the message received on the left).
Subscribe to wildcard topics
Subscribe to the wildcard topic testtopic/# and send a message to the testtopic/1 topic, which will be received in the message list.
This article will show you a「date」between MQTT client and CoAP client in the EMQ X world.
In this project, we will implement remote control LED lights via NodeMCU(ESP8266) and MQTT broker, and use the Arduino IDE to program NodeMCU ESP8266.
This article mainly introduces how to perform TLS/SSL one-way and two-way authentication via Android and MQTT.