Commit 84d76e0ac7faca965a088abab4434cd3832a7c53

Authored by YunaiV
1 parent 7138cab3

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

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 {
247 247 */
248 248 @Data
249 249 public static class Will {
  250 +
250 251 /**
251 252 * 是否启用遗嘱消息
252 253 */
... ... @@ -267,6 +268,7 @@ public class IotGatewayProperties {
267 268 * 遗嘱消息是否作为保留消息发布
268 269 */
269 270 private boolean retain = true;
  271 +
270 272 }
271 273  
272 274 /**
... ... @@ -274,6 +276,7 @@ public class IotGatewayProperties {
274 276 */
275 277 @Data
276 278 public static class Ssl {
  279 +
277 280 /**
278 281 * 密钥库(KeyStore)路径,例如:classpath:certs/client.jks
279 282 * 包含客户端自己的证书和私钥,用于向服务端证明身份(双向认证)。
... ... @@ -292,6 +295,7 @@ public class IotGatewayProperties {
292 295 * 信任库密码
293 296 */
294 297 private String trustStorePassword;
  298 +
295 299 }
296 300  
297 301 }
... ...
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 {
254 254 * 创建 MQTT 客户端
255 255 */
256 256 private void createMqttClient() {
257   - // 1. 创建基础配置
  257 + // 1.1 创建基础配置
258 258 MqttClientOptions options = (MqttClientOptions) new MqttClientOptions()
259 259 .setClientId(emqxProperties.getMqttClientId())
260 260 .setUsername(emqxProperties.getMqttUsername())
... ... @@ -265,8 +265,7 @@ public class IotEmqxUpstreamProtocol {
265 265 .setMaxInflightQueue(emqxProperties.getMaxInflightQueue())
266 266 .setConnectTimeout(emqxProperties.getConnectTimeoutSeconds() * 1000) // Vert.x 需要毫秒
267 267 .setTrustAll(emqxProperties.getTrustAll());
268   -
269   - // 2. 配置遗嘱消息
  268 + // 1.2 配置遗嘱消息
270 269 IotGatewayProperties.EmqxProperties.Will will = emqxProperties.getWill();
271 270 if (will.isEnabled()) {
272 271 Assert.notBlank(will.getTopic(), "遗嘱消息主题(will.topic)不能为空");
... ... @@ -277,30 +276,26 @@ public class IotEmqxUpstreamProtocol {
277 276 .setWillQoS(will.getQos())
278 277 .setWillRetain(will.isRetain());
279 278 }
280   -
281   - // 3. 配置高级 SSL/TLS (仅在启用 SSL 且不信任所有证书时生效)
  279 + // 1.3 配置高级 SSL/TLS (仅在启用 SSL 且不信任所有证书时生效)
282 280 if (Boolean.TRUE.equals(emqxProperties.getMqttSsl()) && !Boolean.TRUE.equals(emqxProperties.getTrustAll())) {
283 281 IotGatewayProperties.EmqxProperties.Ssl sslOptions = emqxProperties.getSslOptions();
284   - // 配置信任库 (用于验证服务端证书)
285 282 if (StrUtil.isNotBlank(sslOptions.getTrustStorePath())) {
286 283 options.setTrustStoreOptions(new JksOptions()
287 284 .setPath(sslOptions.getTrustStorePath())
288 285 .setPassword(sslOptions.getTrustStorePassword()));
289 286 }
290   - // 配置密钥库 (用于客户端双向认证)
291 287 if (StrUtil.isNotBlank(sslOptions.getKeyStorePath())) {
292 288 options.setKeyStoreOptions(new JksOptions()
293 289 .setPath(sslOptions.getKeyStorePath())
294 290 .setPassword(sslOptions.getKeyStorePassword()));
295 291 }
296 292 }
297   -
298   - // 4. 安全警告日志
  293 + // 1.4 安全警告日志
299 294 if (Boolean.TRUE.equals(emqxProperties.getTrustAll())) {
300 295 log.warn("[createMqttClient][安全警告:当前配置信任所有 SSL 证书(trustAll=true),这在生产环境中存在严重安全风险!]");
301 296 }
302 297  
303   - // 5. 创建客户端实例
  298 + // 2. 创建客户端实例
304 299 this.mqttClient = MqttClient.create(vertx, options);
305 300 }
306 301  
... ...
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 {
54 54 });
55 55  
56 56 // 3. 启动 TCP 服务器
57   - netServer.listen(tcpProperties.getServerPort(), "0.0.0.0")
  57 + netServer.listen(tcpProperties.getServerPort())
58 58 .onSuccess(server -> log.info("[start][IoT 网关 TCP 服务启动成功,端口:{}]", server.actualPort()))
59 59 .onFailure(e -> log.error("[start][IoT 网关 TCP 服务启动失败]", e));
60 60 }
... ...