|
@@ -102,13 +102,15 @@ public class MqttManager {
|
|
|
for (String s : topics) {
|
|
for (String s : topics) {
|
|
|
MqttTopicValue mqttTopicValue = new MqttTopicValue();
|
|
MqttTopicValue mqttTopicValue = new MqttTopicValue();
|
|
|
mqttTopicValue.setDevCode(iotDevice.getDevCode());
|
|
mqttTopicValue.setDevCode(iotDevice.getDevCode());
|
|
|
- mqttTopicValue.setServiceName(IotDeviceDictEnum.findServiceNameByDevTypeBid(iotDevice.getDevtypeBid()));
|
|
|
|
|
|
|
+ mqttTopicValue.setServiceName(IotDeviceDictEnum.findServiceNameByDevTypeBid(iotDeviceconnResVo.getDevtypeBid()));
|
|
|
mqttTopicValue.setDevId(iotDevice.getDevBid());
|
|
mqttTopicValue.setDevId(iotDevice.getDevBid());
|
|
|
mqttTopicValue.setTopic(s);
|
|
mqttTopicValue.setTopic(s);
|
|
|
mqttTopicValues.add(mqttTopicValue);
|
|
mqttTopicValues.add(mqttTopicValue);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ iotMqttTopicCacheService.addTopicCache(iotDevice.getDevCode(),topics);
|
|
|
}
|
|
}
|
|
|
|
|
+ mqttTopicValues.toArray();
|
|
|
String[] topics = new String[mqttTopicValues.size()];
|
|
String[] topics = new String[mqttTopicValues.size()];
|
|
|
if (!mqttTopicValues.isEmpty()) {
|
|
if (!mqttTopicValues.isEmpty()) {
|
|
|
for (int i = 0; i < mqttTopicValues.size(); i++) {
|
|
for (int i = 0; i < mqttTopicValues.size(); i++) {
|
|
@@ -130,9 +132,6 @@ public class MqttManager {
|
|
|
mqttCore.buildMqttCore(cfgYf);
|
|
mqttCore.buildMqttCore(cfgYf);
|
|
|
addConnectionMap(connectionId, mqttCore);
|
|
addConnectionMap(connectionId, mqttCore);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- refreshTopicCache();
|
|
|
|
|
-
|
|
|
|
|
log.info("【开始构建MQTT连接】构建完成 devconnId:{} ,devconnName: {}, tosDeviceTypeName:{}, jsonConfig: {}", iotDeviceconnResVo.getDevconnBid(), iotDeviceconnResVo.getDevconnName(), iotDeviceconnResVo.getDevtypeBid(), jsonConfig);
|
|
log.info("【开始构建MQTT连接】构建完成 devconnId:{} ,devconnName: {}, tosDeviceTypeName:{}, jsonConfig: {}", iotDeviceconnResVo.getDevconnBid(), iotDeviceconnResVo.getDevconnName(), iotDeviceconnResVo.getDevtypeBid(), jsonConfig);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.error("【构建MqttCore失败】 异常信息: {} ,{}", e.getMessage(), e);
|
|
log.error("【构建MqttCore失败】 异常信息: {} ,{}", e.getMessage(), e);
|
|
@@ -178,7 +177,6 @@ public class MqttManager {
|
|
|
} finally {
|
|
} finally {
|
|
|
// 从map中移除该MqttCore
|
|
// 从map中移除该MqttCore
|
|
|
mqttCoreMap.remove(connectionId);
|
|
mqttCoreMap.remove(connectionId);
|
|
|
- refreshTopicCache();
|
|
|
|
|
log.info("【从映射中移除MQTT连接】 connectionId: {}", connectionId);
|
|
log.info("【从映射中移除MQTT连接】 connectionId: {}", connectionId);
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
@@ -436,9 +434,6 @@ public class MqttManager {
|
|
|
log.info("【开始单个订阅】 connectionId: {}, serviceName: {}, deviceId: {}", connectionId, serviceName, mqttTopicValues);
|
|
log.info("【开始单个订阅】 connectionId: {}, serviceName: {}, deviceId: {}", connectionId, serviceName, mqttTopicValues);
|
|
|
// 调用批量订阅方法
|
|
// 调用批量订阅方法
|
|
|
topicBatchSubscribeDevices(connectionId, serviceName, mqttTopicValues);
|
|
topicBatchSubscribeDevices(connectionId, serviceName, mqttTopicValues);
|
|
|
-
|
|
|
|
|
- refreshTopicCache();
|
|
|
|
|
-
|
|
|
|
|
log.info("【完成单个订阅】 connectionId: {}, serviceName: {}, deviceId: {}", connectionId, serviceName, mqttTopicValues);
|
|
log.info("【完成单个订阅】 connectionId: {}, serviceName: {}, deviceId: {}", connectionId, serviceName, mqttTopicValues);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -453,7 +448,6 @@ public class MqttManager {
|
|
|
*/
|
|
*/
|
|
|
public void topicBatchUnSubscribeDevices(String connectionId, String serviceName, List<MqttTopicValue> mqttTopicValues) throws MqttException {
|
|
public void topicBatchUnSubscribeDevices(String connectionId, String serviceName, List<MqttTopicValue> mqttTopicValues) throws MqttException {
|
|
|
log.info("【开始批量取消订阅】 connectionId: {}, serviceName: {}, deviceIds: {}", connectionId, serviceName, mqttTopicValues);
|
|
log.info("【开始批量取消订阅】 connectionId: {}, serviceName: {}, deviceIds: {}", connectionId, serviceName, mqttTopicValues);
|
|
|
-
|
|
|
|
|
// 获取批量取消订阅的主题
|
|
// 获取批量取消订阅的主题
|
|
|
String[] topics = deviceTopicService.getBatchTopic(serviceName, mqttTopicValues);
|
|
String[] topics = deviceTopicService.getBatchTopic(serviceName, mqttTopicValues);
|
|
|
log.info("【获取批量取消订阅主题】 topics: {}", Arrays.toString(topics));
|
|
log.info("【获取批量取消订阅主题】 topics: {}", Arrays.toString(topics));
|
|
@@ -470,9 +464,6 @@ public class MqttManager {
|
|
|
log.error("【批量取消订阅失败】 connectionId: {}, serviceName: {}, topics: {}, 异常信息: {}", connectionId, serviceName, Arrays.toString(topics), e.getMessage(), e);
|
|
log.error("【批量取消订阅失败】 connectionId: {}, serviceName: {}, topics: {}, 异常信息: {}", connectionId, serviceName, Arrays.toString(topics), e.getMessage(), e);
|
|
|
throw e;
|
|
throw e;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- refreshTopicCache();
|
|
|
|
|
-
|
|
|
|
|
log.info("【完成批量取消订阅】 connectionId: {}, serviceName: {}, topics: {}", connectionId, serviceName, Arrays.toString(topics));
|
|
log.info("【完成批量取消订阅】 connectionId: {}, serviceName: {}, topics: {}", connectionId, serviceName, Arrays.toString(topics));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -564,23 +555,4 @@ public class MqttManager {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- public void updateCommonConnection(TosDevicetype tosDevicetype, JSONArray jsonConfig) {
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private void refreshTopicCache() {
|
|
|
|
|
- if (true) {
|
|
|
|
|
- //数据量太大,先关闭校验,待优化时候打开
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- Set<String> topicSet = new HashSet<>();
|
|
|
|
|
- for (Map.Entry<String, MqttCore> entry : mqttCoreMap.entrySet()) {
|
|
|
|
|
- MqttCore mqttCore = entry.getValue();
|
|
|
|
|
- Map<String, String> topicToDevId = mqttCore.getTopicToDevId();
|
|
|
|
|
- topicSet.addAll(topicToDevId.keySet());
|
|
|
|
|
- }
|
|
|
|
|
- iotMqttTopicCacheService.refreshTopicCache(topicSet);
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|