This commit is contained in:
houxinyu
2023-07-15 16:51:26 +08:00
parent e6348b08cc
commit e0d6f875ae
11 changed files with 88 additions and 9 deletions

View File

@@ -12,6 +12,7 @@ import com.yomahub.liteflow.parser.redis.exception.RedisException;
import com.yomahub.liteflow.parser.redis.util.RedisParserByPolling;
import com.yomahub.liteflow.parser.redis.util.RedisParserBySubscribe;
import com.yomahub.liteflow.parser.redis.util.RedisParserHelper;
import com.yomahub.liteflow.parser.redis.vo.RedisModeEnum;
import com.yomahub.liteflow.parser.redis.vo.RedisParserVO;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.property.LiteflowConfigGetter;
@@ -54,10 +55,16 @@ public class RedisXmlELParser extends ClassXmlFlowELParser {
checkParserVO(redisParserVO);
//选择订阅机制 or 轮询机制
if (StrUtil.equalsIgnoreCase("subscribe", redisParserVO.getMode())) {
redisParserHelper = new RedisParserBySubscribe(redisParserVO);
} else {
redisParserHelper = new RedisParserByPolling(redisParserVO);
RedisModeEnum mode = redisParserVO.getMode();
switch (mode) {
case SUB:
case SUBSCRIBE:
redisParserHelper = new RedisParserBySubscribe(redisParserVO);
break;
case POLL:
default:
redisParserHelper = new RedisParserByPolling(redisParserVO);
break;
}
}

View File

@@ -207,8 +207,8 @@ public class RedisParserByPolling implements RedisParserHelper{
/**
* 用于轮询chain的定时任务
* 先根据hash中field数量的变化拉取新增的chain
* 再根据hash中value的SHA值修改变化的和被删除的chain
* 先根据hash中value的SHA值修改变化的和被删除的chain
* 再根据hash中field数量的变化拉取新增的chain
*/
private Runnable pollChainTask(String keyLua, String valueLua) {
Runnable r = () -> {

View File

@@ -0,0 +1,25 @@
package com.yomahub.liteflow.parser.redis.vo;
/**
* 用于定义redis规则存储和监听方式的枚举类
*
* @author hxinyu
* @since 2.10.6
*/
public enum RedisModeEnum {
//poll为轮询模式subscribe/sub为订阅模式默认为poll
POLL("poll"),
SUB("subscribe"),
SUBSCRIBE("subscribe");
private String mode;
RedisModeEnum(String mode) {
this.mode = mode;
}
public String getMode() {
return mode;
}
}

View File

@@ -19,7 +19,7 @@ public class RedisParserVO {
private String password;
/*监听机制 轮询为poll 订阅为subscribe 默认为poll*/
private String mode = "poll";
private RedisModeEnum mode = RedisModeEnum.POLL;
/*轮询时间间隔(s) 默认1分钟 若选择订阅机制可不配置*/
//todo 确定类型是string还是long,若为string需校验
@@ -61,12 +61,19 @@ public class RedisParserVO {
this.password = password;
}
public String getMode() {
public RedisModeEnum getMode() {
return mode;
}
public void setMode(String mode) {
this.mode = mode;
mode = mode.toUpperCase();
try{
RedisModeEnum m = RedisModeEnum.valueOf(mode);
this.mode = m;
}
catch (Exception ignored) {
//枚举类转换出错默认为轮询方式
}
}
public String getPollingInterval() {

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>liteflow-testcase-el</artifactId>
<groupId>com.yomahub</groupId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>liteflow-testcase-el-redis-springboot</artifactId>
<dependencies>
</dependencies>
</project>

View File

@@ -0,0 +1,4 @@
package com.yomahub.liteflow.test;
public class BaseTest {
}

View File

@@ -0,0 +1,4 @@
package com.yomahub.liteflow.test.redis;
public class RedisWithXmlELSpringbootTest {
}

View File

@@ -0,0 +1,4 @@
package com.yomahub.liteflow.test.redis.cmp;
public class ACmp {
}

View File

@@ -0,0 +1,4 @@
package com.yomahub.liteflow.test.redis.cmp;
public class BCmp {
}

View File

@@ -0,0 +1,4 @@
package com.yomahub.liteflow.test.redis.cmp;
public class CCmp {
}

View File

@@ -34,6 +34,7 @@
<module>liteflow-testcase-el-script-lua-springboot</module>
<module>liteflow-testcase-el-script-multi-language-springboot</module>
<module>liteflow-testcase-el-script-aviator-springboot</module>
<module>liteflow-testcase-el-redis-springboot</module>
</modules>
<build>