I am getting the following
exception from the mqtt broker when I am trying to
create a new MqttClient. The error is here ---
Caused by: Persistence
already in use (32200) at rg.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence.open(MqttDefaultFilePersistence.java:108)
[mqtt-client-0.4.0.jar:] at org.eclipse.paho.client.mqttv3.MqttAsyncClient.(MqttAsyncClient.java:273)
[mqtt-client-0.4.0.jar:] at org.eclipse.paho.client.mqttv3.MqttClient.(MqttClient.java:222)
[mqtt-client-0.4.0.jar:] at org.eclipse.paho.client.mqttv3.MqttClient.(MqttClient.java:134)
[mqtt-client-0.4.0.jar:] at com.ericsson.asdp.virtualassist.notification.messaging.MQTTHandler.createClient(MQTTHandler.java:61)
[classes:] at com.ericsson.asdp.virtualassist.notification.messaging.MQTTMessagingService.receieve(MQTTMessagingService.java:52)
[classes:] ... 44 more
Here is the code for my java
class receive() method from where I am trying to connect
to mqtt ---
MqttClient subClient = null;
try {
subClient = mqttHandler.createClient(userId, brokerURL);
MQTTNotificationSubscriber notificationSub = new MQTTNotificationSubscriber(mqttHandler);
notificationSub.setUserId(userId);
subClient.setCallback(notificationSub);
mqttHandler.subscribe(subClient, userId);
// do something here
} catch (Exception e) {
logger.error("Error in receive " + e.getMessage());
throw new VirtualAssistServicesException(e.getMessage(), e);
} finally {
try {
mqttHandler.disconnect(subClient);
} catch (MqttException e) {
throw new VirtualAssistServicesException(e.getMessage(), e);
}
}
And here is the MQTTHandler
class createClient() method ---
MqttClient subClient = null;
try {
subClient = new MqttClient(brokerURL, clientId);
} catch (MqttException e) {
}
When I create the client for
a userId first time it works. From second time onwards
when I use the same client Id it fails with the above
exception. I am using clean-session=false here on
purpose.
If anyone has any idea
please let me know. Thanks.