Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[paho-dev] MQTT Connection Lost Error

Hi All,

I am working in an enterprise project and we are using mosquitto broker and mqtt paho client to achieve message communication between our application and other third party applications. From our application we are creating MqttClient to both subscribe and publish operation. While creating the client we are sometimes facing "Client persistence is already in use" exception in the logs. What I suspected is that the client is not closing the previous connection and when we try to create the second client with the same client Id, it is throwing the above error. So I manually closed the connection after processing is done and disconnected. The code snippet - 

MqttClient subClient = new MqttClient(brokerURL, clientId); --- creating the client

For disconnecting ----

client.unsubscribe(configManager.getStringParam(HwaConfigurationConstants.MQTT_SUBSCRIBER_TOPIC) + userId);
client.disconnect(5000);
client.close();

But it still did not work. Then I changed the code a bit to this
MqttClient subClient = new MqttClient(brokerURL, clientId, new MemoryPersistence()); --- creating the client

Now we have not encountered the "Persistence is use " error. But what we are seeing is lot of times "Connection Lost" error is coming in the logs. Any idea here will be highly appreciated as to why this might happen and also if we are creating the client and using persistence in the correct manner.

Thanks,
R Chakrabarti

Back to the top