feat:【IoT 物联网】application 配置文件合并

This commit is contained in:
YunaiV
2025-07-06 10:18:50 +08:00
parent 7138cab3c0
commit 84d76e0ac7
3 changed files with 10 additions and 11 deletions

View File

@@ -247,6 +247,7 @@ public class IotGatewayProperties {
*/
@Data
public static class Will {
/**
* 是否启用遗嘱消息
*/
@@ -267,6 +268,7 @@ public class IotGatewayProperties {
* 遗嘱消息是否作为保留消息发布
*/
private boolean retain = true;
}
/**
@@ -274,6 +276,7 @@ public class IotGatewayProperties {
*/
@Data
public static class Ssl {
/**
* 密钥库KeyStore路径例如classpath:certs/client.jks
* 包含客户端自己的证书和私钥,用于向服务端证明身份(双向认证)。
@@ -292,6 +295,7 @@ public class IotGatewayProperties {
* 信任库密码
*/
private String trustStorePassword;
}
}

View File

@@ -254,7 +254,7 @@ public class IotEmqxUpstreamProtocol {
* 创建 MQTT 客户端
*/
private void createMqttClient() {
// 1. 创建基础配置
// 1.1 创建基础配置
MqttClientOptions options = (MqttClientOptions) new MqttClientOptions()
.setClientId(emqxProperties.getMqttClientId())
.setUsername(emqxProperties.getMqttUsername())
@@ -265,8 +265,7 @@ public class IotEmqxUpstreamProtocol {
.setMaxInflightQueue(emqxProperties.getMaxInflightQueue())
.setConnectTimeout(emqxProperties.getConnectTimeoutSeconds() * 1000) // Vert.x 需要毫秒
.setTrustAll(emqxProperties.getTrustAll());
// 2. 配置遗嘱消息
// 1.2 配置遗嘱消息
IotGatewayProperties.EmqxProperties.Will will = emqxProperties.getWill();
if (will.isEnabled()) {
Assert.notBlank(will.getTopic(), "遗嘱消息主题(will.topic)不能为空");
@@ -277,30 +276,26 @@ public class IotEmqxUpstreamProtocol {
.setWillQoS(will.getQos())
.setWillRetain(will.isRetain());
}
// 3. 配置高级 SSL/TLS (仅在启用 SSL 且不信任所有证书时生效)
// 1.3 配置高级 SSL/TLS (仅在启用 SSL 且不信任所有证书时生效)
if (Boolean.TRUE.equals(emqxProperties.getMqttSsl()) && !Boolean.TRUE.equals(emqxProperties.getTrustAll())) {
IotGatewayProperties.EmqxProperties.Ssl sslOptions = emqxProperties.getSslOptions();
// 配置信任库 (用于验证服务端证书)
if (StrUtil.isNotBlank(sslOptions.getTrustStorePath())) {
options.setTrustStoreOptions(new JksOptions()
.setPath(sslOptions.getTrustStorePath())
.setPassword(sslOptions.getTrustStorePassword()));
}
// 配置密钥库 (用于客户端双向认证)
if (StrUtil.isNotBlank(sslOptions.getKeyStorePath())) {
options.setKeyStoreOptions(new JksOptions()
.setPath(sslOptions.getKeyStorePath())
.setPassword(sslOptions.getKeyStorePassword()));
}
}
// 4. 安全警告日志
// 1.4 安全警告日志
if (Boolean.TRUE.equals(emqxProperties.getTrustAll())) {
log.warn("[createMqttClient][安全警告:当前配置信任所有 SSL 证书trustAll=true这在生产环境中存在严重安全风险]");
}
// 5. 创建客户端实例
// 2. 创建客户端实例
this.mqttClient = MqttClient.create(vertx, options);
}

View File

@@ -54,7 +54,7 @@ public class IotTcpUpstreamProtocol {
});
// 3. 启动 TCP 服务器
netServer.listen(tcpProperties.getServerPort(), "0.0.0.0")
netServer.listen(tcpProperties.getServerPort())
.onSuccess(server -> log.info("[start][IoT 网关 TCP 服务启动成功,端口:{}]", server.actualPort()))
.onFailure(e -> log.error("[start][IoT 网关 TCP 服务启动失败]", e));
}