MQTT

(updated: )
  1. 1. Why MQTT
  2. 2. Concepts
    1. 2.1. Topic
    2. 2.2. Duable
    3. 2.3. Retain
    4. 2.4. QoS (Quality of Service)
  3. 3. Softwares
    1. 3.1. Server
    2. 3.2. Client
  4. 4. Some links

MQ Telemetry Transport

Why MQTT

  • Designed for constrained networks
    – Protocol compressed into bit-wise headers and variable length fields.
    – Smallest possible packet size is 2 bytes
    – Asynchronous bidirectional “push” delivery of messages to applications (no polling)
    • Client to server and server to client – Supports always-connected and sometimes-connected models – Provides Session awareness
    • Configurable keep alive providing granular session awareness
    • “Last will and testament” enable applications to know when a client goes offline abnormally
      – Typically utilises TCP based networks e.g. Webscokets
      – Suitable for IoT, M2M
  • Designed for constrained devices
    • Low CPU, memory, battery

Concepts

Topic

  • A topic forms the namespace
  • Hierarchical with each “sub topic” separated by a /
  • Supports wildcards for subscribers
    • Single-level wildcards “+” can appear anywhere in the topic string
      – Multi-level wildcards “#” must appear at the end of the string
      – Wildcards must be next to a separator

Duable

When subscriber disconnected, messages will be stored on server until the subscriber connects again.

1
MqttConnectOptions.setCleanSession(false);

Retain

A publisher can mark a publication as retained, the server will give this last known good message to new substribers.

1
MqttMessage.setRetained(true);

QoS (Quality of Service)

  • 0: message will be delivered at most once
  • 1: message will be delivered but may be duplicated
  • 2: message will be delivered exactly once

Softwares

Server

Client