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 {
    @Override
    public void process() throws Exception {
        System.out.println("A execute");
    }
}
@Component("b")
public class B extends NodeComponent {
    @Override
    public void process() throws Exception {
        System.out.println("B execute");
    }
}

5.执行规则引擎,通过上面定义的规则名称,chain1,传入参数即可调用

@RestController
public class LiteflowController {

    @Resource
    private FlowExecutor flowExecutor;


    @GetMapping("liteflow/test")
    public Result<String> liteflowTest(){
        LiteflowResponse liteflowResponse = flowExecutor.execute2Resp("chain1", "arg");
        return Result.success("SUCCESS");
    }
}

 

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐