Commit 252366781d38d5e053b000f10c99b88681f0b53e

Authored by YunaiV
1 parent a74459e9

【代码优化】IoT:优化插件 common 和 http 的配置类

Showing 16 changed files with 142 additions and 117 deletions
yudao-dependencies/pom.xml
... ... @@ -600,39 +600,42 @@
600 600 </exclusions>
601 601 </dependency>
602 602  
603   - <!-- MQTT -->
604   - <dependency>
605   - <groupId>org.eclipse.paho</groupId>
606   - <artifactId>org.eclipse.paho.client.mqttv3</artifactId>
607   - <version>${mqtt.version}</version>
608   - </dependency>
609   -
610 603 <!-- PF4J -->
611 604 <dependency>
612 605 <groupId>org.pf4j</groupId>
613 606 <artifactId>pf4j-spring</artifactId>
614 607 <version>${pf4j-spring.version}</version>
  608 + <exclusions>
  609 + <exclusion>
  610 + <groupId>org.slf4j</groupId>
  611 + <artifactId>slf4j-log4j12</artifactId>
  612 + </exclusion>
  613 + </exclusions>
615 614 </dependency>
616 615  
617   - <!-- Vert.x 核心依赖 -->
  616 + <!-- Vert.x -->
618 617 <dependency>
619 618 <groupId>io.vertx</groupId>
620 619 <artifactId>vertx-core</artifactId>
621 620 <version>${vertx.version}</version>
622 621 </dependency>
623   - <!-- Vert.x Web 模块 -->
624 622 <dependency>
625 623 <groupId>io.vertx</groupId>
626 624 <artifactId>vertx-web</artifactId>
627 625 <version>${vertx.version}</version>
628 626 </dependency>
629   - <!-- Vert.x MQTT 模块 -->
630 627 <dependency>
631 628 <groupId>io.vertx</groupId>
632 629 <artifactId>vertx-mqtt</artifactId>
633 630 <version>${vertx.version}</version>
634 631 </dependency>
635 632  
  633 + <!-- MQTT -->
  634 + <dependency>
  635 + <groupId>org.eclipse.paho</groupId>
  636 + <artifactId>org.eclipse.paho.client.mqttv3</artifactId>
  637 + <version>${mqtt.version}</version>
  638 + </dependency>
636 639 </dependencies>
637 640 </dependencyManagement>
638 641  
... ...
yudao-framework/yudao-spring-boot-starter-mybatis/pom.xml
... ... @@ -63,10 +63,6 @@
63 63 <artifactId>opengauss-jdbc</artifactId>
64 64 <optional>true</optional>
65 65 </dependency>
66   - <dependency>
67   - <groupId>com.taosdata.jdbc</groupId>
68   - <artifactId>taos-jdbcdriver</artifactId>
69   - </dependency>
70 66  
71 67 <dependency>
72 68 <groupId>com.alibaba</groupId>
... ...
yudao-module-iot/yudao-module-iot-api/pom.xml
... ... @@ -40,13 +40,6 @@
40 40 <dependency>
41 41 <groupId>org.pf4j</groupId> <!-- PF4J:内置插件机制 -->
42 42 <artifactId>pf4j-spring</artifactId>
43   - <!-- TODO @芋艿:可以放到 bom 里配置 -->
44   - <exclusions>
45   - <exclusion>
46   - <groupId>org.slf4j</groupId>
47   - <artifactId>slf4j-log4j12</artifactId>
48   - </exclusion>
49   - </exclusions>
50 43 </dependency>
51 44  
52 45 <!-- 参数校验 -->
... ...
yudao-module-iot/yudao-module-iot-biz/pom.xml
... ... @@ -52,6 +52,11 @@
52 52 <artifactId>yudao-spring-boot-starter-redis</artifactId>
53 53 </dependency>
54 54  
  55 + <dependency>
  56 + <groupId>com.taosdata.jdbc</groupId>
  57 + <artifactId>taos-jdbcdriver</artifactId>
  58 + </dependency>
  59 +
55 60 <!-- Test 测试相关 -->
56 61 <dependency>
57 62 <groupId>cn.iocoder.boot</groupId>
... ... @@ -64,12 +69,13 @@
64 69 <artifactId>yudao-spring-boot-starter-excel</artifactId>
65 70 </dependency>
66 71  
67   - <!-- 工具类相关 -->
  72 + <!-- TODO @haohao:貌似不需要这个? -->
68 73 <dependency>
69 74 <groupId>io.vertx</groupId>
70 75 <artifactId>vertx-web</artifactId>
71 76 </dependency>
72 77  
  78 + <!-- TODO @haohao:貌似 biz 模块,不需要 MQTT? -->
73 79 <dependency>
74 80 <groupId>org.eclipse.paho</groupId> <!-- MQTT -->
75 81 <artifactId>org.eclipse.paho.client.mqttv3</artifactId>
... ... @@ -78,13 +84,6 @@
78 84 <dependency>
79 85 <groupId>org.pf4j</groupId> <!-- PF4J:内置插件机制 -->
80 86 <artifactId>pf4j-spring</artifactId>
81   - <!-- TODO @芋艿:可以放到 bom 里配置 -->
82   - <exclusions>
83   - <exclusion>
84   - <groupId>org.slf4j</groupId>
85   - <artifactId>slf4j-log4j12</artifactId>
86   - </exclusion>
87   - </exclusions>
88 87 </dependency>
89 88  
90 89 </dependencies>
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/plugininfo/PluginInfoMapper.xml deleted
1   -<?xml version="1.0" encoding="UTF-8"?>
2   -<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3   -<mapper namespace="cn.iocoder.yudao.module.iot.dal.mysql.plugininfo.PluginInfoMapper">
4   -
5   - <!--
6   - 一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
7   - 无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
8   - 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
9   - 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
10   - -->
11   -
12   -</mapper>
13 0 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/plugininstance/PluginInstanceMapper.xml deleted
1   -<?xml version="1.0" encoding="UTF-8"?>
2   -<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3   -<mapper namespace="cn.iocoder.yudao.module.iot.dal.mysql.plugin.IotPluginInstanceMapper">
4   -
5   - <!--
6   - 一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
7   - 无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
8   - 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
9   - 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
10   - -->
11   -
12   -</mapper>
13 0 \ No newline at end of file
yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/pom.xml
... ... @@ -40,6 +40,13 @@
40 40 <groupId>io.vertx</groupId>
41 41 <artifactId>vertx-web</artifactId>
42 42 </dependency>
  43 +
  44 + <!-- 参数校验 -->
  45 + <dependency>
  46 + <groupId>org.springframework.boot</groupId>
  47 + <artifactId>spring-boot-starter-validation</artifactId>
  48 + <optional>true</optional>
  49 + </dependency>
43 50 </dependencies>
44 51  
45 52 </project>
... ...
yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/config/IotPluginCommonAutoConfiguration.java
... ... @@ -3,59 +3,43 @@ package cn.iocoder.yudao.module.iot.plugin.common.config;
3 3 import cn.iocoder.yudao.module.iot.api.device.IotDeviceUpstreamApi;
4 4 import cn.iocoder.yudao.module.iot.plugin.common.downstream.IotDeviceDownstreamHandler;
5 5 import cn.iocoder.yudao.module.iot.plugin.common.downstream.IotDeviceDownstreamServer;
6   -import cn.iocoder.yudao.module.iot.plugin.common.heartbeta.IotPluginInstanceHeartbeatJob;
  6 +import cn.iocoder.yudao.module.iot.plugin.common.heartbeat.IotPluginInstanceHeartbeatJob;
7 7 import cn.iocoder.yudao.module.iot.plugin.common.upstream.IotDeviceUpstreamClient;
8   -import org.springframework.beans.factory.annotation.Value;
9 8 import org.springframework.boot.autoconfigure.AutoConfiguration;
  9 +import org.springframework.boot.context.properties.EnableConfigurationProperties;
10 10 import org.springframework.boot.web.client.RestTemplateBuilder;
11 11 import org.springframework.context.annotation.Bean;
12 12 import org.springframework.scheduling.annotation.EnableScheduling;
13 13 import org.springframework.web.client.RestTemplate;
14 14  
15   -import java.time.Duration;
16   -
17 15 /**
18 16 * IoT 插件的通用自动配置类
19 17 *
20 18 * @author haohao
21 19 */
22 20 @AutoConfiguration
  21 +@EnableConfigurationProperties(IotPluginCommonProperties.class)
23 22 @EnableScheduling // 开启定时任务,因为 IotPluginInstanceHeartbeatJob 是一个定时任务
24 23 public class IotPluginCommonAutoConfiguration {
25 24  
26   - // TODO @haohao:这个要不搞个配置类哈
27   - @Value("${iot.device-data.url}")
28   - private String deviceDataUrl;
29   -
30   - /**
31   - * 创建 RestTemplate 实例
32   - *
33   - * @return RestTemplate 实例
34   - */
35 25 @Bean
36   - public RestTemplate restTemplate() {
37   - // 如果你有更多的自定义需求,比如连接池、超时时间等,可以在这里设置
  26 + public RestTemplate restTemplate(IotPluginCommonProperties properties) {
38 27 return new RestTemplateBuilder()
39   - .connectTimeout(Duration.ofMillis(5000)) // 设置连接超时时间
40   - .readTimeout(Duration.ofMillis(5000)) // 设置读取超时时间
  28 + .connectTimeout(properties.getUpstreamConnectTimeout())
  29 + .readTimeout(properties.getUpstreamReadTimeout())
41 30 .build();
42 31 }
43 32  
44   - /**
45   - * 创建 DeviceDataApi 实例
46   - *
47   - * @param restTemplate RestTemplate 实例
48   - * @return DeviceDataApi 实例
49   - */
50 33 @Bean
51   - public IotDeviceUpstreamApi deviceDataApi(RestTemplate restTemplate) {
52   - return new IotDeviceUpstreamClient(restTemplate, deviceDataUrl);
  34 + public IotDeviceUpstreamApi deviceUpstreamApi(IotPluginCommonProperties properties,
  35 + RestTemplate restTemplate) {
  36 + return new IotDeviceUpstreamClient(properties, restTemplate);
53 37 }
54 38  
55 39 @Bean(initMethod = "start", destroyMethod = "stop")
56   - @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
57   - public IotDeviceDownstreamServer deviceDownstreamServer(IotDeviceDownstreamHandler deviceDownstreamHandler) {
58   - return new IotDeviceDownstreamServer(deviceDownstreamHandler);
  40 + public IotDeviceDownstreamServer deviceDownstreamServer(IotPluginCommonProperties properties,
  41 + IotDeviceDownstreamHandler deviceDownstreamHandler) {
  42 + return new IotDeviceDownstreamServer(properties, deviceDownstreamHandler);
59 43 }
60 44  
61 45 @Bean(initMethod = "init", destroyMethod = "stop")
... ...
yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/config/IotPluginCommonProperties.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.plugin.common.config;
  2 +
  3 +import jakarta.validation.constraints.NotEmpty;
  4 +import lombok.Data;
  5 +import org.springframework.boot.context.properties.ConfigurationProperties;
  6 +import org.springframework.validation.annotation.Validated;
  7 +
  8 +import java.time.Duration;
  9 +
  10 +@ConfigurationProperties(prefix = "yudao.iot.plugin.common")
  11 +@Validated
  12 +@Data
  13 +public class IotPluginCommonProperties {
  14 +
  15 + /**
  16 + * 上行连接超时的默认值
  17 + */
  18 + public static final Duration UPSTREAM_CONNECT_TIMEOUT_DEFAULT = Duration.ofSeconds(30);
  19 + /**
  20 + * 上行读取超时的默认值
  21 + */
  22 + public static final Duration UPSTREAM_READ_TIMEOUT_DEFAULT = Duration.ofSeconds(30);
  23 +
  24 + /**
  25 + * 下行端口 - 随机
  26 + */
  27 + public static final Integer DOWNSTREAM_PORT_RANDOM = 0;
  28 +
  29 + /**
  30 + * 上行 URL
  31 + */
  32 + @NotEmpty(message = "上行 URL 不能为空")
  33 + private String upstreamUrl;
  34 + /**
  35 + * 上行连接超时
  36 + */
  37 + private Duration upstreamConnectTimeout = UPSTREAM_CONNECT_TIMEOUT_DEFAULT;
  38 + /**
  39 + * 上行读取超时
  40 + */
  41 + private Duration upstreamReadTimeout = UPSTREAM_READ_TIMEOUT_DEFAULT;
  42 +
  43 + /**
  44 + * 下行端口
  45 + */
  46 + private Integer downstreamPort = DOWNSTREAM_PORT_RANDOM;
  47 +
  48 +}
... ...
yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/downstream/IotDeviceDownstreamServer.java
1 1 package cn.iocoder.yudao.module.iot.plugin.common.downstream;
2 2  
  3 +import cn.iocoder.yudao.module.iot.plugin.common.config.IotPluginCommonProperties;
3 4 import cn.iocoder.yudao.module.iot.plugin.common.downstream.router.IotDevicePropertyGetVertxHandler;
4 5 import cn.iocoder.yudao.module.iot.plugin.common.downstream.router.IotDevicePropertySetVertxHandler;
5 6 import cn.iocoder.yudao.module.iot.plugin.common.downstream.router.IotDeviceServiceInvokeVertxHandler;
... ... @@ -19,8 +20,11 @@ public class IotDeviceDownstreamServer {
19 20  
20 21 private final Vertx vertx;
21 22 private final HttpServer server;
  23 + private final IotPluginCommonProperties properties;
22 24  
23   - public IotDeviceDownstreamServer(IotDeviceDownstreamHandler deviceDownstreamHandler) {
  25 + public IotDeviceDownstreamServer(IotPluginCommonProperties properties,
  26 + IotDeviceDownstreamHandler deviceDownstreamHandler) {
  27 + this.properties = properties;
24 28 // 创建 Vertx 实例
25 29 this.vertx = Vertx.vertx();
26 30 // 创建 Router 实例
... ... @@ -41,7 +45,7 @@ public class IotDeviceDownstreamServer {
41 45 */
42 46 public void start() {
43 47 log.info("[start][开始启动]");
44   - server.listen(0) // 通过 0 自动选择端口
  48 + server.listen(properties.getDownstreamPort())
45 49 .toCompletionStage()
46 50 .toCompletableFuture()
47 51 .join();
... ...
yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/heartbeta/IotPluginInstanceHeartbeatJob.java renamed to yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/heartbeat/IotPluginInstanceHeartbeatJob.java
1   -package cn.iocoder.yudao.module.iot.plugin.common.heartbeta;
  1 +package cn.iocoder.yudao.module.iot.plugin.common.heartbeat;
2 2  
3 3 import cn.hutool.system.SystemUtil;
4 4 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
... ... @@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.iot.api.device.dto.control.upstream.IotPluginInst
7 7 import cn.iocoder.yudao.module.iot.plugin.common.downstream.IotDeviceDownstreamServer;
8 8 import cn.iocoder.yudao.module.iot.plugin.common.util.IotPluginCommonUtils;
9 9 import lombok.RequiredArgsConstructor;
  10 +import lombok.extern.slf4j.Slf4j;
10 11 import org.springframework.scheduling.annotation.Scheduled;
11 12  
12 13 import java.util.concurrent.TimeUnit;
... ... @@ -17,6 +18,7 @@ import java.util.concurrent.TimeUnit;
17 18 * 用于定时发送心跳给服务端
18 19 */
19 20 @RequiredArgsConstructor
  21 +@Slf4j
20 22 public class IotPluginInstanceHeartbeatJob {
21 23  
22 24 private final IotDeviceUpstreamApi deviceUpstreamApi;
... ... @@ -24,22 +26,22 @@ public class IotPluginInstanceHeartbeatJob {
24 26  
25 27 public void init() {
26 28 CommonResult<Boolean> result = deviceUpstreamApi.heartbeatPluginInstance(buildPluginInstanceHeartbeatReqDTO(true));
27   - // TODO @芋艿:结果的处理
  29 + log.info("[init][上线结果:{})]", result);
28 30 }
29 31  
30 32 public void stop() {
31 33 CommonResult<Boolean> result = deviceUpstreamApi.heartbeatPluginInstance(buildPluginInstanceHeartbeatReqDTO(false));
32   - // TODO @芋艿:结果的处理
  34 + log.info("[stop][下线结果:{})]", result);
33 35 }
34 36  
35 37 @Scheduled(initialDelay = 3, fixedRate = 3, timeUnit = TimeUnit.MINUTES) // 3 分钟执行一次
36 38 public void execute() {
37 39 CommonResult<Boolean> result = deviceUpstreamApi.heartbeatPluginInstance(buildPluginInstanceHeartbeatReqDTO(true));
38   - // TODO @芋艿:结果的处理
  40 + log.info("[execute][心跳结果:{})]", result);
39 41 }
40 42  
41 43 private IotPluginInstanceHeartbeatReqDTO buildPluginInstanceHeartbeatReqDTO(Boolean online) {
42   - // TODO @芋艿:pluginKey 的获取???
  44 + // TODO @haohao:pluginKey 的获取???
43 45 return new IotPluginInstanceHeartbeatReqDTO()
44 46 .setPluginKey("yudao-module-iot-plugin-http").setProcessId(IotPluginCommonUtils.getProcessId())
45 47 .setHostIp(SystemUtil.getHostInfo().getAddress()).setDownstreamPort(deviceDownstreamServer.getPort())
... ...
yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/upstream/IotDeviceUpstreamClient.java
... ... @@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.iot.api.device.dto.control.upstream.IotDeviceEven
6 6 import cn.iocoder.yudao.module.iot.api.device.dto.control.upstream.IotDevicePropertyReportReqDTO;
7 7 import cn.iocoder.yudao.module.iot.api.device.dto.control.upstream.IotDeviceStateUpdateReqDTO;
8 8 import cn.iocoder.yudao.module.iot.api.device.dto.control.upstream.IotPluginInstanceHeartbeatReqDTO;
  9 +import cn.iocoder.yudao.module.iot.plugin.common.config.IotPluginCommonProperties;
9 10 import lombok.RequiredArgsConstructor;
10 11 import lombok.extern.slf4j.Slf4j;
11 12 import org.springframework.web.client.RestTemplate;
... ... @@ -25,32 +26,31 @@ public class IotDeviceUpstreamClient implements IotDeviceUpstreamApi {
25 26  
26 27 public static final String URL_PREFIX = "/rpc-api/iot/device/upstream";
27 28  
28   - private final RestTemplate restTemplate;
  29 + private final IotPluginCommonProperties properties;
29 30  
30   - // TODO @芋艿:改个名字
31   - private final String deviceDataUrl;
  31 + private final RestTemplate restTemplate;
32 32  
33 33 @Override
34 34 public CommonResult<Boolean> updateDeviceState(IotDeviceStateUpdateReqDTO updateReqDTO) {
35   - String url = deviceDataUrl + URL_PREFIX + "/update-state";
  35 + String url = properties.getUpstreamUrl() + URL_PREFIX + "/update-state";
36 36 return doPost(url, updateReqDTO);
37 37 }
38 38  
39 39 @Override
40 40 public CommonResult<Boolean> reportDeviceEvent(IotDeviceEventReportReqDTO reportReqDTO) {
41   - String url = deviceDataUrl + URL_PREFIX + "/report-event";
  41 + String url = properties.getUpstreamUrl() + URL_PREFIX + "/report-event";
42 42 return doPost(url, reportReqDTO);
43 43 }
44 44  
45 45 @Override
46 46 public CommonResult<Boolean> reportDeviceProperty(IotDevicePropertyReportReqDTO reportReqDTO) {
47   - String url = deviceDataUrl + URL_PREFIX + "/report-property";
  47 + String url = properties.getUpstreamUrl() + URL_PREFIX + "/report-property";
48 48 return doPost(url, reportReqDTO);
49 49 }
50 50  
51 51 @Override
52 52 public CommonResult<Boolean> heartbeatPluginInstance(IotPluginInstanceHeartbeatReqDTO heartbeatReqDTO) {
53   - String url = deviceDataUrl + URL_PREFIX + "/heartbeat-plugin-instance";
  53 + String url = properties.getUpstreamUrl() + URL_PREFIX + "/heartbeat-plugin-instance";
54 54 return doPost(url, heartbeatReqDTO);
55 55 }
56 56  
... ...
yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/config/IotPluginHttpAutoConfiguration.java
... ... @@ -4,7 +4,7 @@ import cn.iocoder.yudao.module.iot.api.device.IotDeviceUpstreamApi;
4 4 import cn.iocoder.yudao.module.iot.plugin.common.downstream.IotDeviceDownstreamHandler;
5 5 import cn.iocoder.yudao.module.iot.plugin.http.downstream.IotDeviceDownstreamHandlerImpl;
6 6 import cn.iocoder.yudao.module.iot.plugin.http.upstream.IotDeviceUpstreamServer;
7   -import org.springframework.beans.factory.annotation.Value;
  7 +import org.springframework.boot.context.properties.EnableConfigurationProperties;
8 8 import org.springframework.context.annotation.Bean;
9 9 import org.springframework.context.annotation.Configuration;
10 10  
... ... @@ -14,18 +14,13 @@ import org.springframework.context.annotation.Configuration;
14 14 * @author haohao
15 15 */
16 16 @Configuration
  17 +@EnableConfigurationProperties(IotPluginHttpProperties.class)
17 18 public class IotPluginHttpAutoConfiguration {
18 19  
19   - // TODO @haohao:这个要不要搞个配置类,更容易维护;
20   - /**
21   - * 可在 application.yml 中配置,默认端口 8092
22   - */
23   - @Value("${plugin.http.server.port:8092}")
24   - private Integer port;
25   -
26 20 @Bean(initMethod = "start", destroyMethod = "stop")
27   - public IotDeviceUpstreamServer deviceUpstreamServer(IotDeviceUpstreamApi deviceUpstreamApi) {
28   - return new IotDeviceUpstreamServer(port, deviceUpstreamApi);
  21 + public IotDeviceUpstreamServer deviceUpstreamServer(IotDeviceUpstreamApi deviceUpstreamApi,
  22 + IotPluginHttpProperties properties) {
  23 + return new IotDeviceUpstreamServer(properties, deviceUpstreamApi);
29 24 }
30 25  
31 26 @Bean
... ...
yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/config/IotPluginHttpProperties.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.plugin.http.config;
  2 +
  3 +import lombok.Data;
  4 +import org.springframework.boot.context.properties.ConfigurationProperties;
  5 +import org.springframework.validation.annotation.Validated;
  6 +
  7 +@ConfigurationProperties(prefix = "yudao.iot.plugin.http")
  8 +@Validated
  9 +@Data
  10 +public class IotPluginHttpProperties {
  11 +
  12 + /**
  13 + * HTTP 服务端口
  14 + */
  15 + private Integer serverPort;
  16 +
  17 +}
... ...
yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/upstream/IotDeviceUpstreamServer.java
1 1 package cn.iocoder.yudao.module.iot.plugin.http.upstream;
2 2  
3 3 import cn.iocoder.yudao.module.iot.api.device.IotDeviceUpstreamApi;
  4 +import cn.iocoder.yudao.module.iot.plugin.http.config.IotPluginHttpProperties;
4 5 import cn.iocoder.yudao.module.iot.plugin.http.upstream.router.IotDeviceEventReportVertxHandler;
5 6 import cn.iocoder.yudao.module.iot.plugin.http.upstream.router.IotDevicePropertyReportVertxHandler;
6 7 import io.vertx.core.Vertx;
... ... @@ -21,11 +22,11 @@ public class IotDeviceUpstreamServer {
21 22  
22 23 private final Vertx vertx;
23 24 private final HttpServer server;
24   - private final Integer port;
  25 + private final IotPluginHttpProperties properties;
25 26  
26   - public IotDeviceUpstreamServer(Integer port,
  27 + public IotDeviceUpstreamServer(IotPluginHttpProperties properties,
27 28 IotDeviceUpstreamApi deviceUpstreamApi) {
28   - this.port = port;
  29 + this.properties = properties;
29 30 // 创建 Vertx 实例
30 31 this.vertx = Vertx.vertx();
31 32 // 创建 Router 实例
... ... @@ -44,7 +45,7 @@ public class IotDeviceUpstreamServer {
44 45 */
45 46 public void start() {
46 47 log.info("[start][开始启动]");
47   - server.listen(port)
  48 + server.listen(properties.getServerPort())
48 49 .toCompletionStage()
49 50 .toCompletableFuture()
50 51 .join();
... ...
yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/resources/application.yml
... ... @@ -2,11 +2,11 @@ spring:
2 2 application:
3 3 name: yudao-module-iot-plugin-http
4 4  
5   -iot:
6   - device-data:
7   - url: http://127.0.0.1:48080
8   -
9   -plugin:
10   - http:
11   - server:
12   - port: 8092
13 5 \ No newline at end of file
  6 +yudao:
  7 + iot:
  8 + plugin:
  9 + common:
  10 + upstream-url: http://127.0.0.1:48080
  11 + downstream-port: 8093
  12 + http:
  13 + server-port: 8092
... ...