Commit 2109449a896e465e1740f88315864ed4c00ec298
1 parent
7168e60f
【功能优化】IoT:增加有状态的 Bridge 实现思路
Showing
1 changed file
with
4 additions
and
3 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/IotRuleSceneDataBridgeAction.java
| @@ -11,7 +11,6 @@ import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgTypeEnum; | @@ -11,7 +11,6 @@ import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgTypeEnum; | ||
| 11 | import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum; | 11 | import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum; |
| 12 | import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; | 12 | import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; |
| 13 | import cn.iocoder.yudao.module.iot.service.rule.IotDataBridgeService; | 13 | import cn.iocoder.yudao.module.iot.service.rule.IotDataBridgeService; |
| 14 | -import com.fasterxml.jackson.databind.ObjectMapper; | ||
| 15 | import jakarta.annotation.Resource; | 14 | import jakarta.annotation.Resource; |
| 16 | import lombok.extern.slf4j.Slf4j; | 15 | import lombok.extern.slf4j.Slf4j; |
| 17 | import org.springframework.http.*; | 16 | import org.springframework.http.*; |
| @@ -29,6 +28,9 @@ import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.HEADER_ | @@ -29,6 +28,9 @@ import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.HEADER_ | ||
| 29 | * | 28 | * |
| 30 | * @author 芋道源码 | 29 | * @author 芋道源码 |
| 31 | */ | 30 | */ |
| 31 | +// TODO @芋艿:【优化】因为 bridge 会比较多,所以可以考虑在 rule 下,新建一个 bridge 的 package,然后定义一个 bridgehandler,它有: | ||
| 32 | +// 1. input 方法、output 方法 | ||
| 33 | +// 2. build 方法,用于有状态的连接,例如说 mq、tcp、websocket | ||
| 32 | @Component | 34 | @Component |
| 33 | @Slf4j | 35 | @Slf4j |
| 34 | public class IotRuleSceneDataBridgeAction implements IotRuleSceneAction { | 36 | public class IotRuleSceneDataBridgeAction implements IotRuleSceneAction { |
| @@ -39,8 +41,6 @@ public class IotRuleSceneDataBridgeAction implements IotRuleSceneAction { | @@ -39,8 +41,6 @@ public class IotRuleSceneDataBridgeAction implements IotRuleSceneAction { | ||
| 39 | @Resource | 41 | @Resource |
| 40 | private IotDataBridgeService dataBridgeService; | 42 | private IotDataBridgeService dataBridgeService; |
| 41 | 43 | ||
| 42 | - private final ObjectMapper objectMapper = new ObjectMapper(); | ||
| 43 | - | ||
| 44 | @Override | 44 | @Override |
| 45 | public void execute(IotDeviceMessage message, IotRuleSceneDO.ActionConfig config) { | 45 | public void execute(IotDeviceMessage message, IotRuleSceneDO.ActionConfig config) { |
| 46 | // 1. 获得数据桥梁 | 46 | // 1. 获得数据桥梁 |
| @@ -62,6 +62,7 @@ public class IotRuleSceneDataBridgeAction implements IotRuleSceneAction { | @@ -62,6 +62,7 @@ public class IotRuleSceneDataBridgeAction implements IotRuleSceneAction { | ||
| 62 | return; | 62 | return; |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | + // TODO @芋艿:因为下面的,都是有状态的,所以通过 guava 缓存连接,然后通过 RemovalNotification 实现关闭。例如说,一次新建有效期是 10 分钟; | ||
| 65 | // TODO @芋艿:mq-redis | 66 | // TODO @芋艿:mq-redis |
| 66 | // TODO @芋艿:mq-数据库 | 67 | // TODO @芋艿:mq-数据库 |
| 67 | // TODO @芋艿:kafka | 68 | // TODO @芋艿:kafka |