All Products
Search
Document Center

IoT Platform:Session expiry

Last Updated:Dec 14, 2023

This topic describes the session expiry feature of MQTT 5.0.

Background information

A session specifies information about a connection that is established between a device and IoT Platform and is stored in IoT Platform. The information includes subscription relationship, device status, and cached messages.

  • In MQTT 3.1.1, the cleanSession parameter specifies the session settings.

    • cleanSession = true: A session is deleted when a connection is established. A device must re-subscribe to a topic and does not receive QoS 1 messages that are stored in IoT Platform in a hybrid manner.

    • cleanSession = false: A session is retained when a connection is established. A device does not need to re-subscribe to a topic and receives QoS 1 messages that are stored in IoT Platform in a hybrid manner.

  • In MQTT 5.0, the cleanSession parameter is renamed cleanStart and the Session Expiry Interval property is added. A session can be deleted, retained, or expire. You can configure the Session Expiry Interval property to flexibly manage sessions. If you no longer use sessions, you can delete the sessions to reduce the consumption of IoT Platform resources. This also helps meet the requirements of devices, such as prevent unexpected messages from being received. One of the following cases may occur based on a combination of the values of the Session Expiry Interval property and the cleanStart parameter: image..png

Note
  • If you do not configure the Session Expiry Interval property, the default value 0 is used.

  • If you set the Session Expiry Interval property to 0xFFFFFFFF, the session does not expire.

Scenarios

Devices that are frequently disconnected

If you delete sessions with great frequency for devices that continuously move, such as vehicles, the devices must frequently subscribe to a topic. Case 3 in the preceding figure is suitable for this scenario. If a device reconnects within a specified period of time, reuse the session. If the device cannot connect for a long period of time, delete the session. This way, the device does not receive expired messages.

Devices that cannot lose messages

If you use financial devices, such as POS machines and broadcast speakers, the devices have high requirements for the delivery rate of messages. Case 4 in the preceding figure is suitable for this scenario.

A session remains in the active state from the time when the session starts to the time when the session ends. The corresponding device retains the subscription relationship and the messages.

Status-unrelated devices

If you use devices such as advertisement displays, the devices continuously play new advertisement content and do not need to receive expired messages. Case 1 in the preceding figure is suitable for this scenario.

If you delete sessions, devices no longer receive expired content. This help reduce the consumption of IoT Platform resources.