From 7f58d3e12bcb7ca2f1b163301ecae6ad405a875f Mon Sep 17 00:00:00 2001 From: kerwincui <164770707@qq.com> Date: Thu, 15 May 2025 12:07:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E7=AB=AF=E9=85=8D=E7=BD=AE=E7=AE=80?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application.yml | 14 +++----------- .../common/utils/gateway/mq/TopicsUtils.java | 3 +-- .../com/fastbee/data/service/impl/DeviceJob.java | 3 +-- .../com/fastbee/mqttclient/MqttClientConfig.java | 12 +++++++++--- .../com/fastbee/bootstrap/mqtt/MQTTBootStrap.java | 2 -- .../java/com/fastbee/mqtt/auth/AuthService.java | 5 +---- .../fastbee/mqtt/manager/MqttRemoteManager.java | 3 +-- 7 files changed, 16 insertions(+), 26 deletions(-) diff --git a/springboot/fastbee-admin/src/main/resources/application.yml b/springboot/fastbee-admin/src/main/resources/application.yml index fb1ffa68..09796e25 100644 --- a/springboot/fastbee-admin/src/main/resources/application.yml +++ b/springboot/fastbee-admin/src/main/resources/application.yml @@ -5,7 +5,7 @@ fastbee: copyrightYear: 2024 # 版权年份 demoEnabled: true # 实例演示开关 # 文件路径,以uploadPath结尾 示例( Windows配置 D:/uploadPath,Linux配置 /uploadPath) - profile: /uploadPath + profile: D:/uploadPath addressEnabled: true # 获取ip地址开关 captchaType: math # 验证码类型 math 数组计算 char 字符验证 @@ -22,19 +22,17 @@ server: min-spare: 100 # Tomcat启动初始化的线程数,默认值10 # 基于netty的服务器 broker: - must-pass: false # 客户端连接是否需要密码 - enabled: true # 需要配置为true broker-node: node1 port: 1883 websocket-port: 8083 websocket-path: /mqtt - keep-alive: 30 # 默认的全部客户端心跳上传时间 + keep-alive: 70 # 默认的全部客户端心跳上传时间 # Spring配置 spring: # 环境配置,dev=开发环境,prod=生产环境 profiles: - active: prod # 环境配置,dev=开发环境,prod=生产环境 + active: dev # 环境配置,dev=开发环境,prod=生产环境 # 资源信息 messages: # 国际化资源文件路径 @@ -70,12 +68,6 @@ spring: strict: false lazy: true -#集群配置 -cluster: - enable: true - type: redis - - # 用户配置 user: password: diff --git a/springboot/fastbee-common/src/main/java/com/fastbee/common/utils/gateway/mq/TopicsUtils.java b/springboot/fastbee-common/src/main/java/com/fastbee/common/utils/gateway/mq/TopicsUtils.java index 78f5b659..87895c4d 100644 --- a/springboot/fastbee-common/src/main/java/com/fastbee/common/utils/gateway/mq/TopicsUtils.java +++ b/springboot/fastbee-common/src/main/java/com/fastbee/common/utils/gateway/mq/TopicsUtils.java @@ -24,8 +24,7 @@ import java.util.*; @Component public class TopicsUtils { - @Value("${server.broker.enabled}") - private Boolean enabled; + private Boolean enabled = true; /** * 拼接topic diff --git a/springboot/fastbee-open-api/src/main/java/com/fastbee/data/service/impl/DeviceJob.java b/springboot/fastbee-open-api/src/main/java/com/fastbee/data/service/impl/DeviceJob.java index 7497f5ef..5455fc4b 100644 --- a/springboot/fastbee-open-api/src/main/java/com/fastbee/data/service/impl/DeviceJob.java +++ b/springboot/fastbee-open-api/src/main/java/com/fastbee/data/service/impl/DeviceJob.java @@ -39,8 +39,7 @@ public class DeviceJob { @Resource private IMqttMessagePublish mqttMessagePublish; - @Value("${server.broker.enabled}") - private Boolean enabled; + private Boolean enabled = true; public void updateSipDeviceOnlineStatus(Integer timeout) { String checkTimeCondition = DataBaseHelper.checkTime(timeout); diff --git a/springboot/fastbee-plugs/fastbee-mqtt-client/src/main/java/com/fastbee/mqttclient/MqttClientConfig.java b/springboot/fastbee-plugs/fastbee-mqtt-client/src/main/java/com/fastbee/mqttclient/MqttClientConfig.java index fb9363ed..90dfbbeb 100644 --- a/springboot/fastbee-plugs/fastbee-mqtt-client/src/main/java/com/fastbee/mqttclient/MqttClientConfig.java +++ b/springboot/fastbee-plugs/fastbee-mqtt-client/src/main/java/com/fastbee/mqttclient/MqttClientConfig.java @@ -6,6 +6,8 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import javax.annotation.PostConstruct; + /** * mqtt配置信息 */ @@ -13,15 +15,20 @@ import org.springframework.stereotype.Component; @Data @Component public class MqttClientConfig { - public MqttClientConfig() { + @Value("${server.broker.port}") + private int port; + + @PostConstruct + public void MqttClientConfig() { this.username = "fastbee"; this.password = "fastbee"; - this.hostUrl = "tcp://127.0.0.1:1884"; + this.hostUrl = "tcp://127.0.0.1:" + port; this.clientId = UUID.randomUUID().toString(); this.defaultTopic = "test"; this.timeout = 30; this.keepalive = 30; this.clearSession = true; + this.enabled = true; } /** @@ -69,7 +76,6 @@ public class MqttClientConfig { /** * true: 使用netty搭建的mqttBroker false: 使用emq */ - @Value("${server.broker.enabled}") private Boolean enabled; } diff --git a/springboot/fastbee-server/boot-strap/src/main/java/com/fastbee/bootstrap/mqtt/MQTTBootStrap.java b/springboot/fastbee-server/boot-strap/src/main/java/com/fastbee/bootstrap/mqtt/MQTTBootStrap.java index 37d20449..e6793bcc 100644 --- a/springboot/fastbee-server/boot-strap/src/main/java/com/fastbee/bootstrap/mqtt/MQTTBootStrap.java +++ b/springboot/fastbee-server/boot-strap/src/main/java/com/fastbee/bootstrap/mqtt/MQTTBootStrap.java @@ -44,7 +44,6 @@ public class MQTTBootStrap { * 启动mqttBroker * @return server */ - @ConditionalOnProperty(value = "server.broker.enabled", havingValue = "true") @Bean(initMethod = "start", destroyMethod = "stop") public Server mqttBroker() { return NettyConfig.custom() @@ -56,7 +55,6 @@ public class MQTTBootStrap { .build(); } - @ConditionalOnProperty(value = "server.broker.enabled", havingValue = "true") @Bean(initMethod = "start",destroyMethod = "stop") public Server webSocket(){ return NettyConfig.custom() diff --git a/springboot/fastbee-server/mqtt-broker/src/main/java/com/fastbee/mqtt/auth/AuthService.java b/springboot/fastbee-server/mqtt-broker/src/main/java/com/fastbee/mqtt/auth/AuthService.java index d370a29c..234b8625 100644 --- a/springboot/fastbee-server/mqtt-broker/src/main/java/com/fastbee/mqtt/auth/AuthService.java +++ b/springboot/fastbee-server/mqtt-broker/src/main/java/com/fastbee/mqtt/auth/AuthService.java @@ -36,8 +36,7 @@ public class AuthService { // 令牌秘钥 @Value("${token.secret}") private String secret; - @Value("${server.broker.must-pass}") - private boolean mustPass; + /** * MQTT客户端认证 @@ -48,8 +47,6 @@ public class AuthService { * @return 结果 */ public boolean auth(String clientId, String username, String password) { - //不需要账号密码校验,直接返回true - if (!mustPass) return true; if (StringUtils.isEmpty(clientId) || StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) { log.error("=>客户端参数缺少,clientId:{},username:{},password:{}", clientId, username, password); return false; diff --git a/springboot/fastbee-server/mqtt-broker/src/main/java/com/fastbee/mqtt/manager/MqttRemoteManager.java b/springboot/fastbee-server/mqtt-broker/src/main/java/com/fastbee/mqtt/manager/MqttRemoteManager.java index 4d91e65d..c8c035d5 100644 --- a/springboot/fastbee-server/mqtt-broker/src/main/java/com/fastbee/mqtt/manager/MqttRemoteManager.java +++ b/springboot/fastbee-server/mqtt-broker/src/main/java/com/fastbee/mqtt/manager/MqttRemoteManager.java @@ -26,8 +26,7 @@ public class MqttRemoteManager { /** * true: 使用netty搭建的mqttBroker false: 使用emq */ - @Value("${server.broker.enabled}") - private Boolean enabled; + private Boolean enabled = true; @Resource private PubMqttClient pubMqttClient;