diff --git a/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/config/IotGatewayProperties.java b/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/config/IotGatewayProperties.java index 13635e72ad..737a1560dc 100644 --- a/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/config/IotGatewayProperties.java +++ b/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/config/IotGatewayProperties.java @@ -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; + } } diff --git a/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/emqx/IotEmqxUpstreamProtocol.java b/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/emqx/IotEmqxUpstreamProtocol.java index 48ea281712..a888158746 100644 --- a/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/emqx/IotEmqxUpstreamProtocol.java +++ b/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/emqx/IotEmqxUpstreamProtocol.java @@ -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); } diff --git a/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/tcp/IotTcpUpstreamProtocol.java b/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/tcp/IotTcpUpstreamProtocol.java index 838e2461ef..8e4481a23f 100644 --- a/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/tcp/IotTcpUpstreamProtocol.java +++ b/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/tcp/IotTcpUpstreamProtocol.java @@ -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)); }