فهرست منبع

任务提交 更换mqtt地址

qinguocai 1 سال پیش
والد
کامیت
24e07f988c

+ 7 - 8
ruoyi-framework/src/main/java/com/ruoyi/framework/config/mqtt/MqttInboundConfiguration.java

@@ -58,15 +58,14 @@ public class MqttInboundConfiguration {
 
         //接受离线消息
         options.setCleanSession(false);
-        factory.setConnectionOptions(options);
-
         // 单向ssl/tls
-        try {
-        String caCrtFile = getClass().getResource("/emqxsl-ca.crt").getPath();
-        options.setSocketFactory(SSLUtils.getSingleSocketFactory(caCrtFile));
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        }
+//        try {
+//        String caCrtFile = getClass().getResource("/emqxsl-ca.crt").getPath();
+//        options.setSocketFactory(SSLUtils.getSingleSocketFactory(caCrtFile));
+//        } catch (Exception e) {
+//            throw new RuntimeException(e);
+//        }
+        factory.setConnectionOptions(options);
         return factory;
     }
 

+ 6 - 6
ruoyi-framework/src/main/java/com/ruoyi/framework/config/mqtt/MqttOutboundConfiguration.java

@@ -48,12 +48,12 @@ public class MqttOutboundConfiguration {
         // 接收离线消息
         mqttConnectOptions.setCleanSession(false); //告诉代理客户端是否要建立持久会话   false为建立持久会话
         // 单向ssl/tls
-        try {
-            String caCrtFile = getClass().getResource("/emqxsl-ca.crt").getPath();
-            mqttConnectOptions.setSocketFactory(SSLUtils.getSingleSocketFactory(caCrtFile));
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        }
+//        try {
+//            String caCrtFile = getClass().getResource("/emqxsl-ca.crt").getPath();
+//            mqttConnectOptions.setSocketFactory(SSLUtils.getSingleSocketFactory(caCrtFile));
+//        } catch (Exception e) {
+//            throw new RuntimeException(e);
+//        }
         factory.setConnectionOptions(mqttConnectOptions);
         return factory;
     }

+ 4 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BerthingServiceImpl.java

@@ -110,6 +110,7 @@ public class BerthingServiceImpl implements BerthingService {
             requestMap.put("id",siteInfo.getId());
             requestMap.put("points",positions);
             String data = JSONUtil.toJsonStr(requestMap);
+            log.info("mqtt发送数据:topic:{} data:{}",topic,data);
             mqttGateWayService.sendMessageToMqtt(data, topic);
             return res;
         } catch (Exception e){
@@ -255,6 +256,7 @@ public class BerthingServiceImpl implements BerthingService {
             requestMap.put("positions",positions);
             requestMap.put("factors",berthingPointConfigDTO.getFactors());
             String data = JSONUtil.toJsonStr(requestMap);
+            log.info("mqtt发送数据:topic:{} data:{}",topic,data);
             mqttGateWayService.sendMessageToMqtt(data, topic);
         } catch (Exception e){
             log.error("新增或修改停泊点错误", e);
@@ -333,6 +335,7 @@ public class BerthingServiceImpl implements BerthingService {
             requestMap.put("wlevel",berthingTime.getWlevel());
             requestMap.put("times",times);
             String data = JSONUtil.toJsonStr(requestMap);
+            log.info("mqtt发送数据:topic:{} data:{}",topic,data);
             mqttGateWayService.sendMessageToMqtt(data, topic);
         } catch (Exception e){
             log.error("新增或修改时间策略错误", e);
@@ -413,6 +416,7 @@ public class BerthingServiceImpl implements BerthingService {
             requestMap.put("timespan",berthingFloat.getTimespan());
             requestMap.put("wlevelchange",berthingFloat.getWlevelchange());
             String data = JSONUtil.toJsonStr(requestMap);
+            log.info("mqtt发送数据:topic:{} data:{}",topic,data);
             mqttGateWayService.sendMessageToMqtt(data, topic);
         } catch (Exception e){
             log.error("新增或修改水位变幅策略错误", e);

+ 2 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DirectiveServiceImpl.java

@@ -59,6 +59,7 @@ public class DirectiveServiceImpl implements DirectiveService {
             //TODO 发送mqtt
             String topic = "down/" + siteInfo.getDeviceId() + "/manualMeasure";
             String data = JSONUtil.toJsonStr(requestMap);
+            log.info("mqtt发送数据:topic:{} data:{}",topic,data);
             mqttGateWayService.sendMessageToMqtt(data, topic);
         } catch (Exception e){
             log.error("手动测量下发异常", e);
@@ -117,6 +118,7 @@ public class DirectiveServiceImpl implements DirectiveService {
             requestMap.put("action", action);
             String topic = "down/" + siteInfo.getDeviceId() + "/taskStop";
             String data = JSONUtil.toJsonStr(requestMap);
+            log.info("mqtt发送数据:topic:{} data:{}",topic,data);
             mqttGateWayService.sendMessageToMqtt(data, topic);
         }catch (BaseException e){
             throw e;

+ 4 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SiteServiceImpl.java

@@ -132,6 +132,7 @@ public class SiteServiceImpl implements SiteService {
             SiteConfigMqttDTO siteConfigMqttDTO = new SiteConfigMqttDTO();
             BeanUtils.copyProperties(siteConfig, siteConfigMqttDTO);
             String data = JSONUtil.toJsonStr(siteConfigMqttDTO);
+            log.info("mqtt发送数据:topic:{} data:{}",topic,data);
             mqttGateWayService.sendMessageToMqtt(data, topic);
             return res;
         } catch (BaseException e){
@@ -146,11 +147,13 @@ public class SiteServiceImpl implements SiteService {
     public SiteConfig queryConfig(Long SiteId) {
         try {
             SiteConfig siteConfig = siteConfigMapper.queryBySiteId(SiteId);
+            // 测试后需要删除
 //            SiteInfo siteInfo = siteInfoMapper.queryById(SiteId);
 //            String topic = "down/" + siteInfo.getDeviceId() + "/settings";
 //            SiteConfigMqttDTO siteConfigMqttDTO = new SiteConfigMqttDTO();
 //            BeanUtils.copyProperties(siteConfig, siteConfigMqttDTO);
 //            String data = JSONUtil.toJsonStr(siteConfigMqttDTO);
+//            log.info("mqtt发送数据:topic:{} data:{}",topic,data);
 //            mqttGateWayService.sendMessageToMqtt(data, topic);
             return siteConfig;
         } catch (Exception e){
@@ -185,6 +188,7 @@ public class SiteServiceImpl implements SiteService {
             SiteConfigMqttDTO siteConfigMqttDTO = new SiteConfigMqttDTO();
             BeanUtils.copyProperties(siteConfig, siteConfigMqttDTO);
             String data = JSONUtil.toJsonStr(siteConfigMqttDTO);
+            log.info("mqtt发送数据:topic:{} data:{}",topic,data);
             mqttGateWayService.sendMessageToMqtt(data, topic);
             return res;
         } catch (BaseException e){

+ 1 - 1
waterAffairs-admin/src/main/resources/application.yml

@@ -131,7 +131,7 @@ xss:
 #mqtt
 com:
   mqtt:
-    url: ssl://v5c25d1e.ala.cn-hangzhou.emqxsl.cn:8883 #这里要写 tcp://  不能是 mqtt,不然不是合法的 schema,源码中有
+    url: tcp://47.108.177.6:8085 #这里要写 tcp://  不能是 mqtt,不然不是合法的 schema,源码中有
     clientId: mqtt_test_spring
     receiveTopics: up/#     # IOT device publish msg to web, web receive this to persist
     sendTopics: down/#     # Web Publish msg to iot device, iot device need to subscribe this topic