liteflow是一个轻量级的规则引擎,基于工作台模式,通过抽象出来的组件来将复杂的内部业务逻辑进行解偶,可以在价格,下单等包含复杂业务逻辑的场景中应用。
下面演示一下springboot如何整合liteflow
1.引入依赖
<dependency><groupId>com.yomahub</groupId><artifactId>liteflow-spring-boot-starter</artifactId><version>2.12.4.1</version></dependency>
2.在application中添加配置,指定规则编排的配置文件
liteflow:rule-source: config/flow.el.xml
3.定义规则编排的配置文件,在resource/config下面新建flow.el.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<flow><chain name="chain1">THEN(a, b);</chain>
</flow>
4.定义上面组件的a,b组件
@Component
public class A extends NodeComponent {@Overridepublic void process() throws Exception {System.out.println("A execute");}
}
@Component("b")
public class B extends NodeComponent {@Overridepublic void process() throws Exception {System.out.println("B execute");}
}
5.执行规则引擎,通过上面定义的规则名称,chain1,传入参数即可调用
@RestController
public class LiteflowController {@Resourceprivate FlowExecutor flowExecutor;@GetMapping("liteflow/test")public Result<String> liteflowTest(){LiteflowResponse liteflowResponse = flowExecutor.execute2Resp("chain1", "arg");return Result.success("SUCCESS");}
}