workflow - Hello World
2025年12月21日 下午2:21:45
1、新建项目
新建项目之后,添加依赖
<dependency>
<groupId>org.noear</groupId>
<artifactId>solon-flow</artifactId>
</dependency>
2、添加配置
添加应用配置:
solon.flow:
- "classpath:flow/*.yml"
添加流处理配置(支持 json 或 yml 格式),例: flow/demo1.yml
id: "c1"
layout:
- { id: "n1", type: "start", link: "n2"}
- { id: "n2", type: "activity", link: "n3", task: "System.out.println(\"hello world!\");"}
- { id: "n3", type: "end"}
示意图:

3、代码应用
注解模式
@Configuration
public class DemoCom {
//构建工作流服务
@Bean
public WorkflowService workflowService(FlowEngine engine) {
return WorkflowService.of(engine,
new NotBlockStateController(), //或 BlockStateController, ActorStateController
new InMemoryStateRepository()); //或 RedisStateRepository
}
@Bean
public void test(WorkflowService workflow) throws Throwable {
//获取任务
Task task = workflow.getTask("c1", FlowContext.of("i-1"));
}
}
原生 Java 模式
FlowEngine engine = FlowEngine.newInstance();
WorkflowService workflow = WorkflowService.of(engine,
new NotBlockStateController(), //或 BlockStateController, ActorStateController
new InMemoryStateRepository()); //或 RedisStateRepository
//加载配置
engine.load("classpath:flow/*.yml");
//获取任务
Task task = workflow.getTask("c1", FlowContext.of("i-1"));