From 21c080aa9da3acd53e014e8f917b50a48cb791cb Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期三, 11 六月 2025 13:44:04 +0800 Subject: [PATCH] 进行ApiFox发送内部命令测试,MQTTX发布气象数据测试,修改测试中发现的bug,修改不完善的地方。 --- pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/mqtt/MqttManager.java | 21 ++++++++++++++++++++- 1 files changed, 20 insertions(+), 1 deletions(-) diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/mqtt/MqttManager.java b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/mqtt/MqttManager.java index ac3e211..661696d 100644 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/mqtt/MqttManager.java +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/mqtt/MqttManager.java @@ -10,6 +10,9 @@ import org.apache.logging.log4j.Logger; import org.eclipse.paho.client.mqttv3.MqttClient; +import java.util.ArrayList; +import java.util.List; + /** * @Author: liurunyu * @Date: 2025/6/4 14:54 @@ -24,6 +27,8 @@ private MqttUnitConfigVo configVo ; private MqttClientPool pool; + + private List<MqttClient> subClients ; private MqttManager(){ } @@ -43,8 +48,9 @@ * @throws Exception */ public void start()throws Exception{ + subClients = new ArrayList<>(); String URL = "tcp://" + this.configVo.svIp + ":" + this.configVo.svPort; - this.pool = new MqttClientPool(URL, this.configVo.svUserName, this.configVo.svUserPassword, this.configVo.poolMaxSize); + this.pool = new MqttClientPool(URL, this.configVo.svUserName, this.configVo.svUserPassword, this.configVo.poolMaxSize, this.configVo.useMemoryPersistence); if(this.pool.isClose()){ throw new Exception("Mqtt杩炴帴姹犲垵濮嬪寲澶辫触"); } @@ -57,6 +63,7 @@ if(clientSub == null || !clientSub.isConnected()){ throw new Exception("Mqtt杩炴帴姹犺幏寰楄闃呰繛鎺ヤ笉鍙敤"); } + subClients.add(clientSub) ; // 璁㈤槄涓婚 for(int i = 0; i < this.configVo.subTopics.length; i++){ for(int j = 0 ; j < this.configVo.protocolAndDeviceIds.length; j++){ @@ -90,6 +97,18 @@ } public void stop()throws Exception{ + if(subClients != null && subClients.size() > 0){ + for (MqttClient client : subClients) { + if(client != null && client.isConnected()){ + try{ + client.disconnect(); + client.close(); + }catch (Exception e){ + e.printStackTrace(); + } + } + } + } if(this.pool != null){ // 鍏抽棴杩炴帴姹� this.pool.close(); -- Gitblit v1.8.0