|
@@ -101,7 +101,7 @@ public class MqttManager {
|
|
|
log.info("【创建MqttCore实例】 mqttCore: {} connectionId:{} devSize:{}", mqttCore,connectionId,devices.size());
|
|
log.info("【创建MqttCore实例】 mqttCore: {} connectionId:{} devSize:{}", mqttCore,connectionId,devices.size());
|
|
|
List<MqttTopicValue> mqttTopicValues=new ArrayList<>();
|
|
List<MqttTopicValue> mqttTopicValues=new ArrayList<>();
|
|
|
for(IotDevice iotDevice:devices){
|
|
for(IotDevice iotDevice:devices){
|
|
|
-
|
|
|
|
|
|
|
+ // 根据设备code获取topics
|
|
|
String[] topics= deviceTopicService.getTopic(serviceName, iotDevice.getDevCode());
|
|
String[] topics= deviceTopicService.getTopic(serviceName, iotDevice.getDevCode());
|
|
|
for(String s: topics){
|
|
for(String s: topics){
|
|
|
MqttTopicValue mqttTopicValue=new MqttTopicValue();
|
|
MqttTopicValue mqttTopicValue=new MqttTopicValue();
|
|
@@ -110,7 +110,6 @@ public class MqttManager {
|
|
|
mqttTopicValue.setTopic(s);
|
|
mqttTopicValue.setTopic(s);
|
|
|
mqttTopicValues.add(mqttTopicValue);
|
|
mqttTopicValues.add(mqttTopicValue);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
String[] topics=new String[mqttTopicValues.size()];
|
|
String[] topics=new String[mqttTopicValues.size()];
|
|
@@ -392,16 +391,18 @@ public class MqttManager {
|
|
|
log.info("【开始批量订阅】 connectionId: {}, serviceName: {}, deviceIds: {}", connectionId, serviceName, mqttTopicValues);
|
|
log.info("【开始批量订阅】 connectionId: {}, serviceName: {}, deviceIds: {}", connectionId, serviceName, mqttTopicValues);
|
|
|
|
|
|
|
|
// 获取批量订阅的主题
|
|
// 获取批量订阅的主题
|
|
|
- String[] topics = deviceTopicService.getBatchTopic(serviceName, mqttTopicValues);
|
|
|
|
|
|
|
+ String[] topics = new String[mqttTopicValues.size()];
|
|
|
|
|
+ for(int i=0;i<topics.length;i++){
|
|
|
|
|
+ topics[i]=mqttTopicValues.get(i).getTopic();
|
|
|
|
|
+ }
|
|
|
log.info("【获取批量订阅主题】 topics: {}", Arrays.toString(topics));
|
|
log.info("【获取批量订阅主题】 topics: {}", Arrays.toString(topics));
|
|
|
-
|
|
|
|
|
// 获取MqttCore实例
|
|
// 获取MqttCore实例
|
|
|
MqttCore mqttCore = getMqttCoreByConnectionId(connectionId);
|
|
MqttCore mqttCore = getMqttCoreByConnectionId(connectionId);
|
|
|
log.info("【获取MqttCore实例】 mqttCore: {}", mqttCore);
|
|
log.info("【获取MqttCore实例】 mqttCore: {}", mqttCore);
|
|
|
-
|
|
|
|
|
// 执行订阅
|
|
// 执行订阅
|
|
|
try {
|
|
try {
|
|
|
mqttCore.subscribe(topics);
|
|
mqttCore.subscribe(topics);
|
|
|
|
|
+ mqttCore.bindTopicToDeviceId(mqttTopicValues);
|
|
|
log.info("【批量订阅成功】 connectionId: {}, serviceName: {}, topics: {}, serviceType: {}", connectionId, serviceName, Arrays.toString(topics), mqttCore.getServiceType());
|
|
log.info("【批量订阅成功】 connectionId: {}, serviceName: {}, topics: {}, serviceType: {}", connectionId, serviceName, Arrays.toString(topics), mqttCore.getServiceType());
|
|
|
} catch (MqttException e) {
|
|
} catch (MqttException e) {
|
|
|
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);
|
|
@@ -417,15 +418,11 @@ public class MqttManager {
|
|
|
*
|
|
*
|
|
|
* @param connectionId
|
|
* @param connectionId
|
|
|
* @param serviceName
|
|
* @param serviceName
|
|
|
- * @param mqttTopicValue
|
|
|
|
|
|
|
+ * @param mqttTopicValues
|
|
|
* @throws MqttException
|
|
* @throws MqttException
|
|
|
*/
|
|
*/
|
|
|
- public void topicSingleSubscribeDevice(String connectionId, String serviceName, MqttTopicValue mqttTopicValue) throws MqttException {
|
|
|
|
|
- log.info("【开始单个订阅】 connectionId: {}, serviceName: {}, deviceId: {}", connectionId, serviceName, mqttTopicValue);
|
|
|
|
|
-
|
|
|
|
|
- // 转换为批量订阅
|
|
|
|
|
- List<MqttTopicValue> mqttTopicValues = new ArrayList<>();
|
|
|
|
|
- mqttTopicValues.add(mqttTopicValue);
|
|
|
|
|
|
|
+ public void topicSingleSubscribeDevice(String connectionId, String serviceName, List<MqttTopicValue> mqttTopicValues) throws MqttException {
|
|
|
|
|
+ log.info("【开始单个订阅】 connectionId: {}, serviceName: {}, deviceId: {}", connectionId, serviceName, mqttTopicValues);
|
|
|
// 调用批量订阅方法
|
|
// 调用批量订阅方法
|
|
|
topicBatchSubscribeDevices(connectionId, serviceName, mqttTopicValues);
|
|
topicBatchSubscribeDevices(connectionId, serviceName, mqttTopicValues);
|
|
|
|
|
|