From fe323b176c9adb2369496a1dbc41f1a128a85ae5 Mon Sep 17 00:00:00 2001
From: zhubaomin <zhubaomin>
Date: 星期四, 17 四月 2025 16:46:35 +0800
Subject: [PATCH] 被终止的计划计算轮灌组实际灌溉时长时,如果时长为0则改为1

---
 pipIrr-platform/pipIrr-web/pipIrr-web-app/src/main/java/com/dy/pipIrrApp/workOrder/mqtt/MqttMsgSubscriber.java |   71 +++++++++++++++++++++++++++++++++++
 1 files changed, 71 insertions(+), 0 deletions(-)

diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-app/src/main/java/com/dy/pipIrrApp/workOrder/mqtt/MqttMsgSubscriber.java b/pipIrr-platform/pipIrr-web/pipIrr-web-app/src/main/java/com/dy/pipIrrApp/workOrder/mqtt/MqttMsgSubscriber.java
new file mode 100644
index 0000000..dabba38
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-app/src/main/java/com/dy/pipIrrApp/workOrder/mqtt/MqttMsgSubscriber.java
@@ -0,0 +1,71 @@
+package com.dy.pipIrrApp.workOrder.mqtt;
+
+import lombok.extern.slf4j.Slf4j;
+import org.eclipse.paho.client.mqttv3.*;
+import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
+
+/**
+ * @author ZhuBaoMin
+ * @date 2024-11-16 11:29
+ * @LastEditTime 2024-11-16 11:29
+ * @Description 鍒濆鍖栦竴涓狹qtt瀹㈡埛绔紝骞舵牴鎹厤缃闃卼opic
+ */
+
+@Slf4j
+public class MqttMsgSubscriber {
+
+    public void readSubscribeTopicMessage(){
+        try {
+            //String broker = "tcp://127.0.0.1:1883";
+            //String username = "mqtt_u";
+            //String password = "yjy";
+            //String topic = "workOrder";
+            String broker = "tcp://127.0.0.1:1884";
+            String username = "server";
+            String password = "1234";
+            String topic = "report/#";
+
+            Integer qos = 2;
+            String clientId = System.currentTimeMillis() + "";
+
+            MqttClient client = new MqttClient(broker, clientId, new MemoryPersistence());
+
+            // 杩炴帴鍙傛暟
+            MqttConnectOptions options = new MqttConnectOptions();
+            options.setUserName(username);
+            options.setPassword(password.toCharArray());
+            //鏄惁娓呴櫎浼氳瘽
+            options.setCleanSession(true);
+            options.setConnectionTimeout(60);
+            options.setKeepAliveInterval(60);
+            client.setCallback(new MqttCallback() {
+
+                @Override
+                public void connectionLost(Throwable throwable) {
+                    log.error("杩炴帴涓㈠け");
+                }
+
+                @Override
+                public void messageArrived(String s, MqttMessage mqttMessage) throws Exception {
+                    log.info("topic涓�: " + topic);
+                    log.info("qos涓�: " + mqttMessage.getQos());
+                    log.info("娑堟伅鍐呭涓�: " + new String(mqttMessage.getPayload()));
+                }
+
+                @Override
+                public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
+                    // 褰撴秷鎭瀹屽叏浼犻�佸嚭鍘诲悗璋冪敤
+                    log.info("浜や粯瀹屾垚 ---Delivery complete!");
+                    // 鍙互鍦ㄨ繖閲屽鐞嗕竴浜涘彂閫佸畬鎴愬悗鐨勬竻鐞嗗伐浣�
+                }
+            });
+
+            client.connect(options);
+            client.subscribe(topic, qos);
+        } catch (MqttException e){
+            log.error("MqttMsgSubscriber 杩炴帴鍚姩寮傚父锛歿}", e.getMessage());
+        } catch (Exception e){
+            log.error("MqttMsgSubscriber 璇诲彇娑堟伅寮傚父锛歿}", e.getMessage());
+        }
+    }
+}
\ No newline at end of file

--
Gitblit v1.8.0