Skip to content

Clean sessions ​

An MQTT session is what the broker knows about a client: its subscriptions and the QoS 1/2 messages in flight. The clean session flag (MQTT 3.1.1), or clean start and session expiry (MQTT 5), tell the broker whether to start fresh or continue a previous session.

The flags ​

MQTT 3.1.1MQTT 5
Start a new sessioncleanSession = truecleanStart = true
Ask to continue a previous sessioncleanSession = falsecleanStart = false and a Session Expiry Interval in seconds
Did the broker continue a session?sessionPresent in the CONNACKsessionPresent in the CONNACK

How ConnectMQ handles sessions ​

ConnectMQ starts a new session on every connection. When a client disconnects, its subscriptions and undelivered messages are not kept, whatever the flags say, and the CONNACK of the next connection has sessionPresent = false. The broker may still send a Session Expiry Interval in the CONNACK (for example 1800 seconds on the public test broker); treat it as an upper limit, not as a promise that the session is stored.

What this means for your clients:

  • Subscribe again after every connect. Do it in the connect callback (on('connect'), connectComplete, didConnectAck …), not once at start-up. All code samples in this documentation do this.
  • Messages published while a client is offline are not queued for it. Use retained messages for the latest state, so a client that reconnects reads it at once.
  • Buffer on the publisher side when data must survive an outage: ConnectMQ Edge keeps readings on disk and sends them when the link is back.

cleanSession = true / cleanStart = true is therefore the honest setting for ConnectMQ clients.

Session takeover ​

A client ID can only be connected once. When a second client connects with the same client ID, the broker closes the first connection with 0x8E Session taken over. Two devices sharing an ID keep kicking each other off; give every client a unique suffix (Client IDs & sessions).

A client ID that belongs to another account is refused with 0x85 Client identifier not valid.

Session minutes ​

Every connected client uses session minutes from your plan, one per minute connected, regardless of the session flags (limits).

Fully managed MQTT broker for connected devices.