配套视频：[https://www.bilibili.com/video/BV1mLTAzsEBV/](https://www.bilibili.com/video/BV1mLTAzsEBV/)

### 1、新建项目

可以用 [Solon Initializr](/start/) 生成一个模板项目。新建项目之后，添加依赖

```xml
<dependency>
    <groupId>org.noear</groupId>
    <artifactId>solon-flow</artifactId>
</dependency>
```

### 2、添加配置

添加应用配置：

```yaml
solon.flow:
  - "classpath:flow/*.yml"
```

添加流处理配置（支持 json 或 yml 格式），例： `flow/demo1.yml`

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

示意图：

<img src="/img/ebddfbb4c2e843c5919da57d844c0646.png" width="300" />

### 3、代码应用

注解模式

```java
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 模式

```java
import org.noear.solon.flow.FlowEngine;

FlowEngine engine = FlowEngine.newInstance();

//加载配置
engine.load("classpath:flow/*");

//执行
engine.eval("c1");
```