← Back to the chapter · Previous detail · Next detail →

Technical detail · MQTT Session Management

Session memory and QoS exchange recovery

Message Queuing Telemetry Transport (MQTT) quality of service (QoS) exchanges need saved state as well as a live connection to resume unfinished work. A packet is a unit of network data, a publisher sends messages, a broker routes them, and a subscriber receives messages selected by a subscription.

A session is the saved state that lets the broker remember a client across a break. Its state includes subscriptions, eligible queued messages and QoS exchanges that have not finished. The client also has responsibilities for its side of an exchange. Preserving only the broker’s record cannot restore client state that its process has lost.

QoS 1 uses PUBLISH followed by PUBACK. If the acknowledgement is lost, a resumed exchange may repeat the message. QoS 2 uses PUBLISH, PUBREC, PUBREL and PUBCOMP. The peers keep packet-identifier state to complete that exchange without duplicate protocol delivery on that MQTT leg. A clean session, which starts without saved exchange state, discards in-flight state; a surviving persistent session, which keeps client-related state across connections, can preserve it within its expiry and storage limits.

← Back to the chapter · Previous detail · Next detail →