Search code examples
python-3.xmqttwatson-iot

Durable MQTT session on watson-iot (python


Is it possible to get all missing events if subscriber application is disconnected for a while (e.g. crash)?

I was hoping that setting clean-session to true to get this behavior, but it doesn't work. Here is my code:

import ibmiotf.application

options = {
    "org": "org",
    "id": "some-id",
    "auth-method": "apikey",
    "auth-key": "key",
    "auth-token": "token",
    "clean-session": False
}
client = ibmiotf.application.Client(options)
client.connect()
client.deviceEventCallback = eventCallback
client.subscribeToDeviceEvents(deviceType="deviceType")

Thanks!


Solution

  • You also need to publish the messages with QoS1 or QoS2 and also set

    client.subscribeToDeviceEvents(deviceType="deviceType",qos=1)

    Basically, what you need to do is:

    clean_session =False,

    publish and subscribe qos (quality of service) = 1

    This way the messages that you publish will be received when subscriber will reconnect.

    All the details on watson-iot messaging can be found here. https://console.bluemix.net/docs/services/IoT/reference/mqtt/index.html#qos-levels