后端配置简化

This commit is contained in:
kerwincui
2025-05-15 12:07:16 +08:00
parent 7079610ee4
commit 7f58d3e12b
7 changed files with 16 additions and 26 deletions

View File

@@ -5,7 +5,7 @@ fastbee:
copyrightYear: 2024 # 版权年份
demoEnabled: true # 实例演示开关
# 文件路径以uploadPath结尾 示例( Windows配置 D:/uploadPathLinux配置 /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:

View File

@@ -24,8 +24,7 @@ import java.util.*;
@Component
public class TopicsUtils {
@Value("${server.broker.enabled}")
private Boolean enabled;
private Boolean enabled = true;
/**
* 拼接topic

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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()

View File

@@ -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;

View File

@@ -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;