|
|
@@ -19,6 +19,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.eclipse.paho.client.mqttv3.MqttClient;
|
|
|
import org.eclipse.paho.client.mqttv3.MqttException;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
@@ -78,7 +79,7 @@ public class MqttManager {
|
|
|
* @throws MqttException
|
|
|
*/
|
|
|
public void buildMqttConnection(IotDeviceconnResVo iotDeviceconnResVo, JSONObject jsonConfig) throws MqttException {
|
|
|
- log.info("【开始构建MQTT连接】 tosDeviceTypeName: {}, tosDeviceTypeId:{}, jsonConfig: {}", iotDeviceconnResVo.getDevclassName(), iotDeviceconnResVo.getDevtypeBid(), jsonConfig);
|
|
|
+ log.info("【开始构建MQTT连接】 tosDeviceTypeName: {}, tosDeviceTypeId:{}, jsonConfig: {}", iotDeviceconnResVo.getDevtypeName(), iotDeviceconnResVo.getDevtypeBid(), jsonConfig);
|
|
|
|
|
|
// 构建配置
|
|
|
MqttConfig cfgYf = buildMqttConfig(iotDeviceconnResVo, jsonConfig);
|
|
|
@@ -99,15 +100,16 @@ public class MqttManager {
|
|
|
log.info("【创建MqttCore实例】 mqttCore: {}", mqttCore);
|
|
|
|
|
|
// 查询topics【需要实现:重新更改获取该型号下的设备】
|
|
|
- //String[] topics = deviceTopicService.getBatchTopic(serviceName, deviceTopicService.getDeviceIdByFirmBizId(firmBizId, deviceTypeId));
|
|
|
- String[] topics = deviceTopicService.getBatchTopic(serviceName, new String[]{"", "", ""});
|
|
|
+ String connectionId=iotDeviceconnResVo.getDevconnBid();
|
|
|
+ String[] topics = deviceTopicService.getBatchTopic(serviceName, deviceTopicService.getDeviceCodesByConectionId(connectionId));
|
|
|
+ //String[] topics = deviceTopicService.getBatchTopic(serviceName, new String[]{"", "", ""});
|
|
|
cfgYf.setSubTopic(topics);
|
|
|
cfgYf.setServiceName(serviceName);
|
|
|
log.info("【初始化厂商加载配置】 {} {} {}", firmName, type, Arrays.toString(topics));
|
|
|
|
|
|
- // 处理连接ID的逻辑
|
|
|
- log.info("【添加公共连接】 connectionId: connectionId");
|
|
|
- addConnectionMap("connectionId", mqttCore);
|
|
|
+ // 处理连接ID的逻辑 IP+port+name
|
|
|
+ log.info("【添加公共连接】 connectionId: {}",connectionId);
|
|
|
+ addConnectionMap(connectionId, mqttCore);
|
|
|
|
|
|
// 构建MqttCore
|
|
|
try {
|
|
|
@@ -177,7 +179,7 @@ public class MqttManager {
|
|
|
cfgYf.setType(type);
|
|
|
//其他信息
|
|
|
cfgYf.setFirmName(iotDeviceconnResVo.getFirmName());
|
|
|
- cfgYf.setDeviceType(DevType.valueOfCode(iotDeviceconnResVo.getDevtypeBid()));
|
|
|
+ cfgYf.setDeviceType(iotDeviceconnResVo.getDevtypeName());
|
|
|
cfgYf.setDeviceTypeBizId(iotDeviceconnResVo.getDevtypeBid());
|
|
|
|
|
|
cfgYf.setIp(jsonConfig.getString("ip"));
|
|
|
@@ -548,4 +550,14 @@ public class MqttManager {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 模拟异步发送
|
|
|
+ *
|
|
|
+ * @param msg
|
|
|
+ */
|
|
|
+ @Async
|
|
|
+ public void receiveMsg(String msg) throws InterruptedException {
|
|
|
+ Thread.sleep(5000);
|
|
|
+
|
|
|
+ }
|
|
|
}
|