2026-06-24 f4bd1f3c89d906131495a0aca5aaf82966378510
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
package cn.iocoder.yudao.module.iot.gateway.config;
 
import cn.iocoder.yudao.module.iot.core.enums.IotProtocolTypeEnum;
import cn.iocoder.yudao.module.iot.gateway.protocol.coap.IotCoapConfig;
import cn.iocoder.yudao.module.iot.gateway.protocol.emqx.IotEmqxConfig;
import cn.iocoder.yudao.module.iot.gateway.protocol.http.IotHttpConfig;
import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpclient.IotModbusTcpClientConfig;
import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.IotModbusTcpServerConfig;
import cn.iocoder.yudao.module.iot.gateway.protocol.mqtt.IotMqttConfig;
import cn.iocoder.yudao.module.iot.gateway.protocol.tcp.IotTcpConfig;
import cn.iocoder.yudao.module.iot.gateway.protocol.udp.IotUdpConfig;
import cn.iocoder.yudao.module.iot.gateway.protocol.websocket.IotWebSocketConfig;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;
 
import java.time.Duration;
import java.util.List;
 
@ConfigurationProperties(prefix = "yudao.iot.gateway")
@Validated
@Data
public class IotGatewayProperties {
 
    /**
     * 设备 RPC 服务配置
     */
    private RpcProperties rpc;
    /**
     * Token 配置
     */
    private TokenProperties token;
 
    /**
     * 协议实例列表
     */
    private List<ProtocolProperties> protocols;
 
    @Data
    public static class RpcProperties {
 
        /**
         * 主程序 API 地址
         */
        @NotEmpty(message = "主程序 API 地址不能为空")
        private String url;
        /**
         * 连接超时时间
         */
        @NotNull(message = "连接超时时间不能为空")
        private Duration connectTimeout;
        /**
         * 读取超时时间
         */
        @NotNull(message = "读取超时时间不能为空")
        private Duration readTimeout;
 
    }
 
    @Data
    public static class TokenProperties {
 
        /**
         * 密钥
         */
        @NotEmpty(message = "密钥不能为空")
        private String secret;
        /**
         * 令牌有效期
         */
        @NotNull(message = "令牌有效期不能为空")
        private Duration expiration;
 
    }
 
    /**
     * 协议实例配置
     */
    @Data
    public static class ProtocolProperties {
 
        /**
         * 协议实例 ID,如 "http-alink"、"tcp-binary"
         */
        @NotEmpty(message = "协议实例 ID 不能为空")
        private String id;
        /**
         * 是否启用
         */
        @NotNull(message = "是否启用不能为空")
        private Boolean enabled = true;
        /**
         * 协议类型
         *
         * @see cn.iocoder.yudao.module.iot.core.enums.IotProtocolTypeEnum
         */
        @NotEmpty(message = "协议类型不能为空")
        private String protocol;
        /**
         * 服务端口
         * <p>
         * 不同协议含义不同:
         * 1. TCP/UDP/HTTP/WebSocket/MQTT/CoAP:对应网关自身监听的服务端口
         * 2. EMQX:对应网关提供给 EMQX 回调的 HTTP Hook 端口(/mqtt/auth、/mqtt/acl、/mqtt/event)
         */
        @NotNull(message = "服务端口不能为空")
        private Integer port;
        /**
         * 序列化类型(可选)
         *
         * @see cn.iocoder.yudao.module.iot.core.enums.IotSerializeTypeEnum
         *
         * 为什么是可选的呢?
         * 1. {@link IotProtocolTypeEnum#HTTP}、{@link IotProtocolTypeEnum#COAP} 协议,目前强制是 JSON 格式
         * 2. {@link IotProtocolTypeEnum#EMQX} 协议,目前支持根据产品(设备)配置的序列化类型来解析
         */
        private String serialize;
 
        // ========== SSL 配置 ==========
 
        /**
         * SSL 配置(可选,配置文件中不配置则为 null)
         */
        @Valid
        private SslConfig ssl;
 
        // ========== 各协议配置 ==========
 
        /**
         * HTTP 协议配置
         */
        @Valid
        private IotHttpConfig http;
        /**
         * WebSocket 协议配置
         */
        @Valid
        private IotWebSocketConfig websocket;
 
        /**
         * TCP 协议配置
         */
        @Valid
        private IotTcpConfig tcp;
        /**
         * UDP 协议配置
         */
        @Valid
        private IotUdpConfig udp;
 
        /**
         * CoAP 协议配置
         */
        @Valid
        private IotCoapConfig coap;
 
        /**
         * MQTT 协议配置
         */
        @Valid
        private IotMqttConfig mqtt;
        /**
         * EMQX 协议配置
         */
        @Valid
        private IotEmqxConfig emqx;
 
        /**
         * Modbus TCP Client 协议配置
         */
        @Valid
        private IotModbusTcpClientConfig modbusTcpClient;
 
        /**
         * Modbus TCP Server 协议配置
         */
        @Valid
        private IotModbusTcpServerConfig modbusTcpServer;
 
    }
 
    /**
     * SSL 配置
     */
    @Data
    public static class SslConfig {
 
        /**
         * 是否启用 SSL
         */
        @NotNull(message = "是否启用 SSL 不能为空")
        private Boolean ssl = false;
 
        /**
         * SSL 证书路径
         */
        @NotEmpty(message = "SSL 证书路径不能为空")
        private String sslCertPath;
 
        /**
         * SSL 私钥路径
         */
        @NotEmpty(message = "SSL 私钥路径不能为空")
        private String sslKeyPath;
 
        /**
         * 密钥库(KeyStore)路径
         * <p>
         * 包含客户端自己的证书和私钥,用于向服务端证明身份(双向认证)
         */
        private String keyStorePath;
        /**
         * 密钥库密码
         */
        private String keyStorePassword;
 
        /**
         * 信任库(TrustStore)路径
         * <p>
         * 包含服务端信任的 CA 证书,用于验证服务端的身份
         */
        private String trustStorePath;
        /**
         * 信任库密码
         */
        private String trustStorePassword;
 
    }
 
}