feat: 完善 iot-gateway 生产环境配置

- 添加 IoT 网关特有的配置项环境变量支持
- 支持 HTTP/MQTT/TCP/EMQX 协议配置
- 支持设备 RPC 和 Token 配置
- 支持消息总线配置
- 添加生产环境配置文档
This commit is contained in:
lzh
2026-01-13 12:32:14 +08:00
parent 2b9c1aa7d8
commit f9aa7828c7
2 changed files with 264 additions and 21 deletions

View File

@@ -23,7 +23,7 @@ spring:
port: ${REDIS_PORT:6379}
database: ${REDIS_DATABASE:0}
password: ${REDIS_PASSWORD:}
timeout: 5000ms
timeout: ${REDIS_TIMEOUT:30000ms}
lettuce:
pool:
max-active: 8
@@ -35,21 +35,83 @@ spring:
rocketmq:
name-server: ${ROCKETMQ_NAMESRV_ADDR:127.0.0.1:9876}
producer:
group: ${spring.application.name}_PRODUCER
spring:
rabbitmq:
host: ${RABBITMQ_HOST:127.0.0.1}
port: ${RABBITMQ_PORT:5672}
username: ${RABBITMQ_USERNAME:guest}
password: ${RABBITMQ_PASSWORD:guest}
kafka:
bootstrap-servers: ${KAFKA_BOOTSTRAP_SERVERS:127.0.0.1:9092}
--- #################### IoT 网关相关配置 ####################
--- #################### 服务保障相关配置 ####################
viewsh:
iot:
# 消息总线配置
message-bus:
type: ${IOT_MESSAGE_BUS_TYPE:redis}
lock4j:
acquire-timeout: 3000
expire: 30000
# 网关配置
gateway:
# 设备 RPC 配置
rpc:
url: ${IOT_RPC_URL:http://127.0.0.1:48091}
connect-timeout: ${IOT_RPC_CONNECT_TIMEOUT:30s}
read-timeout: ${IOT_RPC_READ_TIMEOUT:30s}
# 设备 Token 配置
token:
secret: ${IOT_TOKEN_SECRET:viewshIotGatewayTokenSecret123456789}
expiration: ${IOT_TOKEN_EXPIRATION:7d}
# 协议配置
protocol:
# HTTP 协议配置
http:
enabled: ${IOT_HTTP_ENABLED:true}
server-port: ${IOT_HTTP_PORT:8092}
# EMQX 协议配置
emqx:
enabled: ${IOT_EMQX_ENABLED:false}
http-port: ${IOT_EMQX_HTTP_PORT:8090}
mqtt-host: ${IOT_EMQX_MQTT_HOST:127.0.0.1}
mqtt-port: ${IOT_EMQX_MQTT_PORT:1883}
mqtt-username: ${IOT_EMQX_MQTT_USERNAME:admin}
mqtt-password: ${IOT_EMQX_MQTT_PASSWORD:public}
mqtt-client-id: ${IOT_EMQX_MQTT_CLIENT_ID:iot-gateway-mqtt}
mqtt-ssl: ${IOT_EMQX_MQTT_SSL:false}
mqtt-topics:
- "/sys/#"
clean-session: true
keep-alive-interval-seconds: 60
max-inflight-queue: 10000
connect-timeout-seconds: 10
trust-all: false # 生产环境必须为 false
will:
enabled: true
topic: "gateway/status/${viewsh.iot.gateway.emqx.mqtt-client-id}"
payload: "offline"
qos: 1
retain: true
ssl-options:
key-store-path: ${IOT_EMQX_SSL_KEYSTORE_PATH:classpath:certs/client.jks}
key-store-password: ${IOT_EMQX_SSL_KEYSTORE_PASSWORD:}
trust-store-path: ${IOT_EMQX_SSL_TRUSTSTORE_PATH:classpath:certs/trust.jks}
trust-store-password: ${IOT_EMQX_SSL_TRUSTSTORE_PASSWORD:}
# TCP 协议配置
tcp:
enabled: ${IOT_TCP_ENABLED:false}
port: ${IOT_TCP_PORT:8091}
keep-alive-timeout-ms: ${IOT_TCP_KEEPALIVE_TIMEOUT:30000}
max-connections: ${IOT_TCP_MAX_CONNECTIONS:1000}
ssl-enabled: ${IOT_TCP_SSL_ENABLED:false}
ssl-cert-path: ${IOT_TCP_SSL_CERT_PATH:classpath:certs/client.jks}
ssl-key-path: ${IOT_TCP_SSL_KEY_PATH:classpath:certs/client.jks}
# MQTT 协议配置
mqtt:
enabled: ${IOT_MQTT_ENABLED:true}
port: ${IOT_MQTT_PORT:1883}
max-message-size: ${IOT_MQTT_MAX_MESSAGE_SIZE:8192}
connect-timeout-seconds: ${IOT_MQTT_CONNECT_TIMEOUT:60}
ssl-enabled: ${IOT_MQTT_SSL_ENABLED:false}
--- #################### 监控相关配置 ####################
@@ -69,18 +131,19 @@ spring:
username: ${SPRING_BOOT_ADMIN_USERNAME:admin}
password: ${SPRING_BOOT_ADMIN_PASSWORD:admin}
--- #################### 日志相关配置 ####################
logging:
level:
root: INFO
com.viewsh: ${LOG_LEVEL:INFO}
com.viewsh.module.iot.gateway: ${LOG_LEVEL_IOT_GATEWAY:INFO}
org.springframework.boot: INFO
org.apache.rocketmq: WARN
com.viewsh.module.iot.gateway.protocol.emqx: ${LOG_LEVEL_EMQX:INFO}
com.viewsh.module.iot.gateway.protocol.http: ${LOG_LEVEL_HTTP:INFO}
com.viewsh.module.iot.gateway.protocol.mqtt: ${LOG_LEVEL_MQTT:INFO}
file:
name: ${LOG_FILE_PATH:/app/logs}/${spring.application.name}.log
--- #################### 芋道相关配置 ####################
debug: false
viewsh:
demo: false
env:
tag: ${HOSTNAME:prod}
security:
mock-enable: false