當我嘗試創建新的MqttClient時,我從mqtt代理獲取以下異常。該錯誤是在這裏---獲取持久性已使用來自MQTT的錯誤
Caused by: Persistence already in use (32200)
at org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence.open(MqttDefaultFilePersistence.java:108) [mqtt-client-0.4.0.jar:]
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.<init>(MqttAsyncClient.java:273) [mqtt-client-0.4.0.jar:]
at org.eclipse.paho.client.mqttv3.MqttClient.<init>(MqttClient.java:222) [mqtt-client-0.4.0.jar:]
at org.eclipse.paho.client.mqttv3.MqttClient.<init>(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
這是從那裏我試圖連接到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);
}
}
我的java類方法的代碼這裏是MQTTHandler createClient()
類方法---
MqttClient subClient = null;
try {
subClient = new MqttClient(brokerURL, clientId);
} catch (MqttException e) {
}
當我第一次爲userId創建客戶端時,它工作。從第二次起,它不符合上述例外。我在這裏使用clean-session=false
。
如果有人有任何想法,請讓我知道。謝謝。
如果使用MemoryPersistence而不是默認的FilePersistence,問題會得到解決。 @Alessandro,thx爲你的職位。對於我的情況,我不希望維護單獨的clientID-s;這是一種需求。因此,我現在使用MemoryPersistence,它工作正常;至少現在:) – chakrar