MQTT (Message Queuing Telemetry Transport)- API Architecture Style Every Developer Must Know

MQTT stands for MQ Telemetry Transport. MQTT is the most commonly used messaging protocol for the Internet of Things (IoT). The protocol is a set of rules that defines how IoT devices can publish and subscribe to data over the Internet. MQTT is used for messaging and data exchange between IoT and industrial IoT (IIoT) devices, such as embedded devices, sensors, industrial PLCs, etc. The protocol is event driven and connects devices using the publish /subscribe (Pub/Sub) pattern. The sender (Publisher) and the receiver (Subscriber) communicate via Topics and are decoupled from each other. The connection between them is handled by the MQTT broker. The MQTT broker filters all incoming messages and distributes them correctly to the Subscribers.

MQTT Message Queuing Telemetry Transport

Why MQTT?

Lightweight and Efficient

MQTT clients are very small, require minimal resources so can be used on small microcontrollers. MQTT message headers are small to optimize network bandwidth.

Support for Unreliable Networks

Many IoT devices connect over unreliable cellular networks. MQTT’s support for persistent sessions reduces the time to reconnect the client with the broker.

Bi-directional Communications

MQTT allows for messaging between device to cloud and cloud to device. This makes for easy broadcasting messages to groups of things.

Reliable Message Delivery

Reliability of message delivery is important for many IoT use cases. This is why MQTT has 3 defined quality of service levels: 0 – at most once, 1- at least once, 2 – exactly once

Scale to Millions of Things

MQTT can scale to connect with millions of IoT devices.

Security Enabled
 

MQTT makes it easy to encrypt messages using TLS and authenticate clients using modern authentication protocols, such as OAuth.

MQTT Publish / Subscribe Architecture

mqtt-api-publish-subscribe

MQTT in Action - Use Cases

Automotive
  • HiveMQ: BMW Car-Sharing application relies on HiveMQ for reliable connectivity.

    BMW Mobility Services has been using HiveMQ and MQTT for over 4 years. This experience has given them some unique insight into building IoT solutions using this technology. They have some recommendations for others that are investigating MQTT and HiveMQ:

    • If scalability is important to your solution, set up a cluster early in the process to understand how to scale MQTT systems.

    • Talk to other people which have gone through the process of scaling MQTT to help you navigate the issues.

    • Introducing MQTT into a development organization requires education and training. There are lots of online resources available to help but also reach out to the community to understand best practices and limitations of MQTT.

  • EMQ helps SAIC Volkswagen building IoV platform. – SAIC Volkswagen’s IoV solution is based on EMQ Technologies’ EMQX Enterprise platform, which provides massive connection capacity and high concurrent message throughput. It supports data persistence, southward message caching, secure connections and secure authentication.
Logistics
Manufacturing
Smart Home
Oil & Gas
Consumer Products
Transportation

MQTT Key Features

MQTT Clients

MQTT Clients

MQTT clients publish a message to an MQTT broker and other MQTT clients subscribe to messages they want to receive. Implementations of MQTT clients typically require a minimal footprint so are well suited for deployment on small constrained devices and are very efficient in their bandwidth requirements.
HiveMQ develops a Java-based MQTT client that is available under an open source license.

MQTT Broker

MQTT Broker

MQTT brokers receive published messages and dispatch the message to the subscribing MQTT clients. An MQTT message contains a message topic that MQTT clients subscribe to and MQTT brokers use these subscription lists for determining the MQTT clients to receive the message.
HiveMQ offers a commercial and open source MQTT broker.

 

MQTT QoS (Quality of Service) Levels

MQTT QoS (Quality of Service) Levels

MQTT implements 3 quality of service levels for agreement between the sender and receiver:

1) At most once (0),

2) At least once (1), and

3) Exactly once (2).

These QoS levels allow for more reliable IoT applications since the underlying messaging infrastructure and adapt to unreliable network conditions.

 

Persistent Sessions

Persistent Sessions

MQTT allows for a persistent session between the client and the broker. This allows for sessions to persist even if the network is disconnected. Once the network is reconnected, the information to reconnect the client to the broker still exists. This is one of the key features that makes the MQTT protocol more efficient than HTTP for use over unreliable cellular networks.

 

Retained Messages

Retained Messages

MQTT clients that subscribe to a new topic have no insight into when to expect the first message they will receive. However, an MQTT broker can store a retained message that can be sent immediately upon a new MQTT subscription. In this case, the MQTT client will receive at least one message upon subscribing to the topic.

 

Last Will and Testament (LWT)

Last Will and Testament (LWT)

An MQTT client can specify to an MQTT broker a message, called the last will, that will be sent if the MQTT client ungracefully disconnects. This allows for a more graceful system wide notification that a client has been disconnected.

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top