flow - 五大特色
1、采用 yaml 或 json 偏平式编排格式
偏平式编排,没有深度结构(所有节点平铺,使用 link 描述连接关系)。配置简洁,关系清晰
# c1.yml
id: "c1"
layout:
- { id: "n1", type: "start", link: "n2"}
- { id: "n2", type: "activity", link: "n3"}
- { id: "n3", type: "end"}
还支持简化模式(能自动推断的,都会自动处理),具体参考相关说明
# c1.yml
id: "c1"
layout:
- { type: "start"}
- { task: ""}
- { type: "end"}
2、表达式与脚本自由
# c2.yml
id: "c2"
layout:
- { type: "start"}
- { when: "order.getAmount() >= 100", task: "order.setScore(0);"}
- { when: "order.getAmount() > 100 && order.getAmount() <= 500", task: "order.setScore(100);"}
- { when: "order.getAmount() > 500 && order.getAmount() <= 1000", task: "order.setScore(500);"}
- { type: "end"}
3、元数据配置,为扩展提供了无限空间
元数据主要有两个作用:(1)为任务运行提供配置支持(2)为视图编辑提供配置支持
# c3.yml
id: "c3"
layout:
- { id: "n1", type: "start", link: "n2"}
- { id: "n2", type: "activity", link: "n3", meta: {cc: "demo@noear.org"}, task: "@MetaProcessCom"}
- { id: "n3", type: "end"}
通过组件方式,实现元数据的抄送配置效果
@Component("MetaProcessCom")
public class MetaProcessCom implements TaskComponent {
@Override
public void run(FlowContext context, Node node) throws Throwable {
String cc = node.getMeta("cc");
if(Utils.isNotEmpty(cc)){
//发送邮件...
}
}
}
4、事件广播与回调支持
广播(即只需要发送),回调(即发送后要求给答复)
id: f4
layout:
- task: |
//只发送
context.<String,String>eventBus().send("demo.topic", "hello"); //支持泛型(类型按需指定,不指定时为 object)
- task: |
//发送并要求响应(就是要给答复)
String rst = context.<String,String>eventBus().sendAndRequest("demo.topic.get", "hello");
System.out.println(rst);
5、支持无状态、有状态两种应用场景
支持丰富的应用场景:
- 无状态流程
- 可用于计算(或任务)的编排场景
- 可用于业务规则和决策处理型的编排场景
- 有状态流程
- 可用于办公审批型(有状态、可中断,人员参与)的编排场景
- 可用于长时间流程(结合自动前进,等待介入)的编排场景
自身也相当于一个低代码的运行引擎(单个配置文件,也可满足所有的执行需求)。