flow - Hello World
配套视频:https://www.bilibili.com/video/BV1mLTAzsEBV/
1、新建项目
可以用 Solon Initializr 生成一个模板项目。新建项目之后,添加依赖
<dependency>
<groupId>org.noear</groupId>
<artifactId>solon-flow</artifactId>
</dependency>
2、添加配置
添加应用配置:
solon.flow:
- "classpath:flow/*.yml"
添加流处理配置(支持 json 或 yml 格式),例: flow/demo1.chain.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、代码应用
注解模式
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
import org.noear.solon.core.bean.LifecycleBean;
import org.noear.solon.flow.FlowEngine;
@Component
public class DemoCom implements LifecycleBean {
@Inject
private FlowEngine flowEngine;
@Override
public void start() throws Throwable {
flowEngine.eval("c1");
}
}
原生 Java 模式
import org.noear.solon.flow.FlowEngine;
FlowEngine engine = FlowEngine.newInstance();
//加载链配置
engine.load("classpath:flow/*");
//执行
engine.eval("c1");