compileflow 是什么compileflow 是一个非常轻量、高性能、可集成、可扩展的流程引擎。 compileflow Process 引擎是淘宝工作流 TBBPM 引擎之一,是专注于纯内存执行,无状态的流程引擎,通过将流程文件转换生成 java 代码编译执行,简洁高效。当前是阿里业务中台交易等多个核心系统的流程引擎。 compileflow 能让开发人员通过流程编辑器设计自己的业务流程,将复杂的业务逻辑可视化,为业务设计人员与开发工程师架起了一座桥梁。 功能列表- 高性能:通过将流程文件转换生成 java 代码编译执行,简洁高效。
- 丰富的应用场景:在阿里巴巴中台解决方案中广泛使用,支撑了导购、交易、履约、资金等多个业务场景。
- 可集成:轻量、简洁的设计使得可以极其方便地集成到各个解决方案和业务场景中。
- 完善的插件支持:流程设计目前有 IntelliJ IDEA、Eclipse 插件支持,可以在流程设计中实时动态生成 java 代码并预览,所见即所得。
- 支持基于 Java 反射和 Spring 容器的代码触发
快速上手<dependency> <groupId>com.alibaba.compileflow</groupId> <artifactId>compileflow</artifactId> <version>1.0.0</version> </dependency>
- 查看编译出的流程业务 Java 代码(以下代码为 compileflow 自动根据流程图生成的)
public class PigFlow implements ProcessInstance {
private java.lang.Integer price = null;
public Map<String, Object> execute(Map<String, Object> _pContext) throws Exception { price = (Integer)DataType.transfer(_pContext.get("price"), Integer.class); Map<String, Object> _pResult = new HashMap<>(); decision8(); //AutoTaskNode: 付款 ((BizMock)ObjectFactory.getInstance("com.example.compileflow.bean.BizMock")).payMoney(price); _pResult.put("price", price); return _pResult; }
private void decision8() { //DecisionNode: 计算费用 bizMockCalMoney(); if (price>=100) { //超过100 { //ScriptTaskNode: 春哥请客 腿打折 IExpressContext<String, Object> nfScriptContext = new DefaultContext<>(); nfScriptContext.put("price", price); price = (java.lang.Integer)ScriptExecutorProvider.getInstance().getScriptExecutor("QL").execute("price*2", nfScriptContext); } } else { //不超过100 { //ScriptTaskNode: 冷冷请客 打5折 IExpressContext<String, Object> nfScriptContext = new DefaultContext<>(); nfScriptContext.put("price", price); price = (java.lang.Integer)ScriptExecutorProvider.getInstance().getScriptExecutor("QL").execute("(round(price*0.5,0)).intValue()", nfScriptContext); } } }
private void bizMockCalMoney() { price = ((BizMock)ObjectFactory.getInstance("com.example.compileflow.bean.BizMock")).calMoney(price); }
}
@Test public void testProcess() throws Exception { String code = "pig"; ProcessEngine<TbbpmModel> engine = ProcessEngineFactory.getProcessEngine(); System.out.println(engine.getJavaCode(code)); Map<String, Object> context = new HashMap<>(); context.put("price", 10);
Map<String, Object> execute = engine.execute(code, context);
System.out.println(execute); }
假装在计算金额~~~~~~10 支付了~~~~~~5
总结compileflow 极其容易上手,降低工作流学习的难度。 compileflow IDEA 设计插件[1]在 2021 版本兼容性存在问题。 自动生成的单元测试代码依赖版本较低不支持 Junit5
参考资料[1]compileflow IDEA 设计插件: https://github.com/compileflow/compileflow-designer-upgrade
|