flow - 五大特色
2025年12月21日 下午12:17:25
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", task: "@MetaProcessCom", meta: {cc: "demo@noear.org"}}
- { 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.eventBus().send("demo.topic", "hello"); //支持泛型(类型按需指定,不指定时为 object)
- task: |
//调用事件(就是要给答复)
String rst = context.eventBus().<String, String>call("demo.topic.get", "hello").get();
System.out.println(rst);
5、支持驱动定制(就像 jdbc 的驱动机制)
通过驱动定制,可方便实现:
- 工作流(workflow), 用于办公审批型(有节点状态、人员参与)的编排场景
- 规则流(ruleflow)
- 数据流(dataflow)
- AI流(aiflow)
- 等...