Hello @Ben Hoffman,
You're correct that Azure IoT Hub only allows one session per device identity at a time. If a new connection is made with the same device identity while another session is still active, the previous session is forcibly disconnected.
Thus, if you reconnect with the same identity, the previous session will be disconnected. To resume a session and retain messages, set clean_session = false
and reconnect with the same identity. Note that you cannot resume a session with a different identity, because sessions are tied to specific devices.
Creating a new session requires setting clean_session = true
, which resets all previous subscriptions and messages.
To test message persistence across disconnections, disconnect at 1.5× Keepalive, ensure clean_session = false
, and use QoS 1 for guaranteed delivery.
For more details, refer to this MSDOC for the Azure IoT Client MQTT State Machine.
Alternatively, if you need multiple endpoints connected to the Azure IoT Hub, you can either use unique device IDs per endpoint or use AMQP device multiplexing. Please note that there are currently bugs in this feature in azure-iot-sdk-c.
Hope this helps!
If you found this answer helpful, please click Accept Answer and consider upvoting it /click yes.
If you have any further questions, please click Comment.