Commit 14336002f364707c4bc900a75047189dce7fcb85
1 parent
73e97d16
review:【iot 物联网】mqtt 协议
Showing
5 changed files
with
6 additions
and
8 deletions
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/config/IotGatewayProperties.java
| @@ -353,7 +353,6 @@ public class IotGatewayProperties { | @@ -353,7 +353,6 @@ public class IotGatewayProperties { | ||
| 353 | * 连接超时时间(秒) | 353 | * 连接超时时间(秒) |
| 354 | */ | 354 | */ |
| 355 | private Integer connectTimeoutSeconds = 60; | 355 | private Integer connectTimeoutSeconds = 60; |
| 356 | - | ||
| 357 | /** | 356 | /** |
| 358 | * 保持连接超时时间(秒) | 357 | * 保持连接超时时间(秒) |
| 359 | */ | 358 | */ |
| @@ -363,7 +362,6 @@ public class IotGatewayProperties { | @@ -363,7 +362,6 @@ public class IotGatewayProperties { | ||
| 363 | * 是否启用 SSL | 362 | * 是否启用 SSL |
| 364 | */ | 363 | */ |
| 365 | private Boolean sslEnabled = false; | 364 | private Boolean sslEnabled = false; |
| 366 | - | ||
| 367 | /** | 365 | /** |
| 368 | * SSL 配置 | 366 | * SSL 配置 |
| 369 | */ | 367 | */ |
| @@ -379,27 +377,22 @@ public class IotGatewayProperties { | @@ -379,27 +377,22 @@ public class IotGatewayProperties { | ||
| 379 | * 密钥证书选项 | 377 | * 密钥证书选项 |
| 380 | */ | 378 | */ |
| 381 | private io.vertx.core.net.KeyCertOptions keyCertOptions; | 379 | private io.vertx.core.net.KeyCertOptions keyCertOptions; |
| 382 | - | ||
| 383 | /** | 380 | /** |
| 384 | * 信任选项 | 381 | * 信任选项 |
| 385 | */ | 382 | */ |
| 386 | private io.vertx.core.net.TrustOptions trustOptions; | 383 | private io.vertx.core.net.TrustOptions trustOptions; |
| 387 | - | ||
| 388 | /** | 384 | /** |
| 389 | * SSL 证书路径 | 385 | * SSL 证书路径 |
| 390 | */ | 386 | */ |
| 391 | private String certPath; | 387 | private String certPath; |
| 392 | - | ||
| 393 | /** | 388 | /** |
| 394 | * SSL 私钥路径 | 389 | * SSL 私钥路径 |
| 395 | */ | 390 | */ |
| 396 | private String keyPath; | 391 | private String keyPath; |
| 397 | - | ||
| 398 | /** | 392 | /** |
| 399 | * 信任存储路径 | 393 | * 信任存储路径 |
| 400 | */ | 394 | */ |
| 401 | private String trustStorePath; | 395 | private String trustStorePath; |
| 402 | - | ||
| 403 | /** | 396 | /** |
| 404 | * 信任存储密码 | 397 | * 信任存储密码 |
| 405 | */ | 398 | */ |
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/mqtt/IotMqttUpstreamProtocol.java
| @@ -50,6 +50,7 @@ public class IotMqttUpstreamProtocol { | @@ -50,6 +50,7 @@ public class IotMqttUpstreamProtocol { | ||
| 50 | this.serverId = IotDeviceMessageUtils.generateServerId(mqttProperties.getPort()); | 50 | this.serverId = IotDeviceMessageUtils.generateServerId(mqttProperties.getPort()); |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | + // TODO @haohao:这里的编写,是不是和 tcp 对应的,风格保持一致哈; | ||
| 53 | @PostConstruct | 54 | @PostConstruct |
| 54 | public void start() { | 55 | public void start() { |
| 55 | // 创建服务器选项 | 56 | // 创建服务器选项 |
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/mqtt/manager/IotMqttConnectionManager.java
| @@ -46,7 +46,9 @@ public class IotMqttConnectionManager { | @@ -46,7 +46,9 @@ public class IotMqttConnectionManager { | ||
| 46 | } | 46 | } |
| 47 | } catch (Exception e) { | 47 | } catch (Exception e) { |
| 48 | // 忽略异常,返回默认值 | 48 | // 忽略异常,返回默认值 |
| 49 | + // TODO @haohao:这个比较稳定会出现哇? | ||
| 49 | } | 50 | } |
| 51 | + // TODO @haohao:这个要枚举下么? | ||
| 50 | return "unknown"; | 52 | return "unknown"; |
| 51 | } | 53 | } |
| 52 | 54 | ||
| @@ -194,4 +196,5 @@ public class IotMqttConnectionManager { | @@ -194,4 +196,5 @@ public class IotMqttConnectionManager { | ||
| 194 | private boolean authenticated; | 196 | private boolean authenticated; |
| 195 | 197 | ||
| 196 | } | 198 | } |
| 199 | + | ||
| 197 | } | 200 | } |
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/mqtt/router/IotMqttDownstreamHandler.java
| @@ -69,7 +69,6 @@ public class IotMqttDownstreamHandler { | @@ -69,7 +69,6 @@ public class IotMqttDownstreamHandler { | ||
| 69 | 69 | ||
| 70 | // 5. 发送消息到设备 | 70 | // 5. 发送消息到设备 |
| 71 | return sendMessageToDevice(message, connectionInfo, payload); | 71 | return sendMessageToDevice(message, connectionInfo, payload); |
| 72 | - | ||
| 73 | } catch (Exception e) { | 72 | } catch (Exception e) { |
| 74 | if (message != null) { | 73 | if (message != null) { |
| 75 | log.error("[handleDownstreamMessage][处理下行消息异常,设备 ID:{},错误:{}]", | 74 | log.error("[handleDownstreamMessage][处理下行消息异常,设备 ID:{},错误:{}]", |
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/mqtt/router/IotMqttUpstreamHandler.java
| @@ -40,6 +40,7 @@ public class IotMqttUpstreamHandler { | @@ -40,6 +40,7 @@ public class IotMqttUpstreamHandler { | ||
| 40 | 40 | ||
| 41 | public IotMqttUpstreamHandler(IotMqttUpstreamProtocol protocol, | 41 | public IotMqttUpstreamHandler(IotMqttUpstreamProtocol protocol, |
| 42 | IotDeviceMessageService deviceMessageService, | 42 | IotDeviceMessageService deviceMessageService, |
| 43 | + // TODO @haohao:用不到的 deviceService 可以删除哈; | ||
| 43 | IotDeviceService deviceService, | 44 | IotDeviceService deviceService, |
| 44 | IotMqttConnectionManager connectionManager) { | 45 | IotMqttConnectionManager connectionManager) { |
| 45 | this.deviceMessageService = deviceMessageService; | 46 | this.deviceMessageService = deviceMessageService; |
| @@ -70,6 +71,7 @@ public class IotMqttUpstreamHandler { | @@ -70,6 +71,7 @@ public class IotMqttUpstreamHandler { | ||
| 70 | 71 | ||
| 71 | log.info("[handle][设备认证成功,建立连接,客户端 ID: {},用户名: {}]", clientId, username); | 72 | log.info("[handle][设备认证成功,建立连接,客户端 ID: {},用户名: {}]", clientId, username); |
| 72 | 73 | ||
| 74 | + // TODO @haohao:这里是不是少了序号哈? | ||
| 73 | // 设置异常和关闭处理器 | 75 | // 设置异常和关闭处理器 |
| 74 | endpoint.exceptionHandler(ex -> { | 76 | endpoint.exceptionHandler(ex -> { |
| 75 | log.warn("[handle][连接异常,客户端 ID: {},地址: {}]", clientId, getEndpointAddress(endpoint)); | 77 | log.warn("[handle][连接异常,客户端 ID: {},地址: {}]", clientId, getEndpointAddress(endpoint)); |