|
|
5 maanden geleden | |
|---|---|---|
| .. | ||
| yudao-module-iot-net-component-core | 5 maanden geleden | |
| yudao-module-iot-net-component-emqx | 7 maanden geleden | |
| yudao-module-iot-net-component-http | 7 maanden geleden | |
| yudao-module-iot-net-component-server | 7 maanden geleden | |
| README.md | 7 maanden geleden | |
| pom.xml | 7 maanden geleden | |
该模块包含多个 IoT 设备连接组件,提供不同的通信协议支持:
yudao-module-iot-net-component-core: 核心接口和通用类yudao-module-iot-net-component-http: 基于 HTTP 协议的设备通信组件yudao-module-iot-net-component-emqx: 基于 MQTT/EMQX 的设备通信组件各组件采用统一的架构设计和命名规范:
IotComponentXxxAutoConfiguration - 提供Bean定义和组件初始化逻辑IotComponentXxxProperties - 定义组件的配置属性*DownstreamHandler - 处理从平台到设备的下行通信*UpstreamServer - 处理从设备到平台的上行通信为避免 Bean 冲突,各个组件中的 Bean 已添加特定前缀:
httpDeviceUpstreamServer, httpDeviceDownstreamHandleremqxDeviceUpstreamServer, emqxDeviceDownstreamHandler现在系统支持同时使用多个组件,但有以下规则:
yudao.iot.component.emqx.enabled=true时,核心模块将优先使用EMQX组件@Qualifier指定要使用的具体实现重要提示:
- 组件库内部的默认配置文件不会被自动加载。必须将上述配置添加到主应用的配置文件中。
- 所有配置项现在都已增加空值处理,配置缺失时将使用合理的默认值
mqtt-host是唯一必须配置的参数,其他参数均有默认值mqtt-ssl和auth-port缺失时的默认值分别为false和8080mqtt-topics缺失时将使用默认主题/device/#
在其他组件中引用这些 Bean 时,需要使用 @Qualifier 注解指定 Bean 名称:
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import cn.iocoder.yudao.module.iot.component.core.downstream.IotDeviceDownstreamHandler;
@Service
public class YourServiceClass {
// 注入 HTTP 组件的下行处理器
@Autowired
@Qualifier("httpDeviceDownstreamHandler")
private IotDeviceDownstreamHandler httpDeviceDownstreamHandler;
// 注入 EMQX 组件的下行处理器
@Autowired
@Qualifier("emqxDeviceDownstreamHandler")
private IotDeviceDownstreamHandler emqxDeviceDownstreamHandler;
// 使用示例
public void example() {
// 使用 HTTP 组件
httpDeviceDownstreamHandler.invokeDeviceService(...);
// 使用 EMQX 组件
emqxDeviceDownstreamHandler.invokeDeviceService(...);
}
}
如果遇到以下日志:
MQTT配置: host=null, port=null, username=null, ssl=null
[connectMqtt][MQTT Host为null,无法连接]
这表明配置没有被正确加载。请确保:
application.yml 或 application-dev.yml)添加了必要的 EMQX 配置yudao.iot.component.emqxmqtt-host 属性如果遇到以下错误:
Cannot invoke "java.lang.Boolean.booleanValue()" because the return value of "cn.iocoder.yudao.module.iot.component.emqx.config.IotEmqxComponentProperties.getMqttSsl()" is null
此问题已通过代码修复,现在会自动使用默认值 false。同样适用于其他配置项的空值问题。
如果遇到以下错误:
Cannot invoke "java.lang.Integer.intValue()" because the return value of "cn.iocoder.yudao.module.iot.component.emqx.config.IotEmqxComponentProperties.getAuthPort()" is null
此问题已通过代码修复,现在会自动使用默认值 8080。
如果遇到以下错误:
Parameter 1 of method deviceDownstreamServer in IotPluginCommonAutoConfiguration required a single bean, but 2 were found
此问题已通过修改核心配置类来解决。现在系统会根据组件的启用状态自动选择合适的实现:
yudao.iot.component.emqx.enabled=true时)yudao.iot.component.http.enabled=true时)如果需要同时使用两个组件,业务代码中必须使用@Qualifier明确指定要使用的Bean。
组件现已加入完善的默认配置和空值处理机制,使配置更加灵活。但需要注意的是,这些默认配置值必须通过在主应用配置文件中设置相应的属性才能生效。
// TODO 芋艿:后续继续完善 README.md