What is The MQTT and Why is it the Best Protocol for IoT?

MQTT Protocol Introduction

Overview

  • Simple and easy to implement
  • QoS support (complex device network environment)
  • Lightweight and bandwidth-saving (because bandwidth was expensive back then)
  • Data irrelevant (Payload data format does not matter)
  • Continuous session awareness (always know whether the device is online)

Comparison Between MQTT and Other Protocols

  • With a minimum message size of 2 bytes, MQTT takes up less network overhead than HTTP.
  • Both MQTT and HTTP can use TCP connections and achieve stable and reliable network connections.
  • MQTT is based on a publish-subscribe model and HTTP is based on request-response, so MQTT supports duplex communication.
  • MQTT can push messages in real-time, but HTTP needs polling for data updates.
  • MQTT is stateful, but HTTP is stateless.
  • MQTT can recover connections from abnormal disconnections, which HTTP cannot achieve.
  • MQTT messages are small and easy to encode and decode, while XMPP is based on heavy XML, and the messages are large and cumbersome to interact with.
  • MQTT is based on a publish-subscribe model, which is more flexible than XMPP’s JID-based point-to-point message routing.
  • MQTT supports different types of messages such as JSON, binary, etc. XMPP uses XML to carry messages, and binary must be Base64 encoded and processed by other methods.
  • MQTT guarantees reliable message transmission through QoS; the XMPP protocol does not define a similar mechanism.

Why is MQTT The Best Protocol for IoT?

Lightweight and Efficient

Reliable Message Delivery

  • QoS 0: The message is transmitted at most once.
  • QoS 1: The message is transmitted at least once.
  • QoS 2: The message is transmitted only once.

Connect Massive IoT Devices

Secure Bi-directional Communication

Keep Alive and Stateful Sessions

MQTT 5.0 and MQTT 3.1.1

MQTT Broker

docker run -d --name emqx -p 1883:1883 -p 8083:8083 -p 8084:8084 -p 8883:8883 -p 18083:18083 emqx/emqx:latest

MQTT Client

Quick Start with MQTT

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
EMQ Technologies

EMQ is an open-source IoT data infrastructure software provider, delivering the world’s leading open-source MQTT message broker and stream processing database.