Manish Kumar
Manish Kumar

Reputation: 10502

Paho doesn't subscribe to earlier topic on reconnect

Everytime I connect using JS paho client with the same client id, It is not subscribing to the topics that I had subscribed earlier.

mqttClient = new Paho.MQTT.Client(constants.MQTT_HOST, Number(constants.MQTT_PORT), '/ws', "User-" + this.getCurrentUserDetails().id);

Upvotes: 1

Views: 1494

Answers (1)

hardillb
hardillb

Reputation: 59638

The mqttClient.connect() method takes an options object which includes the cleanSession flag, the default value for this field is true.

When cleanSession is set to true then all existing subscriptions and any queued messages are cleared when the new connection is formed. If you want persistent subscriptions then you will need to set this to false.

For more details, HiveMQ have a nice blog post about sessions here

Upvotes: 1

Related Questions