Solon v3.8.3

flow - 六大特色

</> markdown
2026年1月13日 下午7:56:39

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"}

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"}

4、上下文快照持久化:中断与恢复

支持输出快照(Snapshot)。对于需要人工审批、等待回调或长达数天的长流程,可将当前运行状态序列化保存,待触发后随时恢复运行。

// 1. 在任务内根据情况停止执行
context.stop();

// 2. 在节点执行停止后,保存状态
String snapshotJson = context.toJson(); 
db.save(instanceId, json);

// 3. 经过一段时间后,从中断处恢复(继续执行)
String snapshotJson = db.get(instanceId);
FlowContext context = FlowContext.fromJson(snapshotJson);
flowEngine.eval(graph, context);

5、事件广播与回调支持

内置 EventBus,支持组件间的异步解耦或同步调用。

//发送事件
context.eventBus().send("demo.topic", "hello");  //支持泛型(类型按需指定,不指定时为 object)

//调用事件(就是要给答复)
String rst = context.eventBus().<String, String>call("demo.topic.get", "hello").get();
System.out.println(rst);

6、支持驱动定制(就像 jdbc 的驱动机制)

通过驱动定制,可快速实现:工作流(Workflow)、规则流(RuleFlow)、数据流(DataFlow)及 AI 智能流。