Flow engine usage - jd-opensource/jd-easyflow GitHub Wiki
Integration description
There are quickstart test cases in test folder of sources. You can run or debug to learn the usage and principle.
Basic
See https://github.com/jd-opensource/jd-easyflow/blob/master/README.md
Spring
Inject FlowEngine and use as normal bean. Demo are as follows:
@Bean
public FlowEngine flowEngine() {
FlowEngineImpl flowEngineImpl = new FlowEngineImpl();
flowEngineImpl.setFlowPath("classpath*:flow/**/*.json");
return flowEngineImpl;
}
Invoke demo:
@Autowired
private FlowEngine flowEngine;
// java code...
FlowParam param = new FlowParam(flowId, startNodeId, bizData);
FlowResult result = flowEngine.execute(param);
Flow definition description
Overall description
| First level | Second level | Third level | Name | Description |
|---|---|---|---|---|
| id | Flow ID | Global unique | ||
| name | Flow name | |||
| pre | Flow pre handler | string or object type | ||
| createExp | EL creating pre handler | the return type should be FlowPreHandler type | ||
| nodes | Node list | array type | ||
| id | Node ID | Unique in flow | ||
| name | Node name | |||
| start | start node flag | boolean type | ||
| properties | node properties | object type | ||
| pre | node pre handler | |||
| createExp | EL creating pre handler | the return type should by NodePreHandler type | ||
| exp | EL to execute | |||
| type | pre handler type | multiCheck/inclusiveCheck | ||
| preNodes | pre nodes list | |||
| action | Node action | string or object type | ||
| exp | Spel expression to execute | |||
| createExp | Spel expression of creating NodeAction | return value should be NodeAction type | ||
| flow | Subflow definition | |||
| flowId | Subflow id | |||
| startNodeId | Start node(s) of subflow | |||
| post | Node post handler | |||
| createExp | EL creating post handler | the return type should be NodePostHanlder type | ||
| exp | EL to execute | |||
| other config | see description bellow about post | |||
| post | Flow post handler | string or object type | ||
| createExp | EL creating post handler | the return type should be FlowPostHandler type | ||
| listeners | Listener list | |||
| createExp | Create expression of listener | |||
| filters | Filter list | |||
| nodeFilters | Node filter list | |||
| nodePreHandlerFilters | Node PreHandler filter list | |||
| nodeActionFilters | Node action filter list | |||
| nodePostHandlerFilters | Node PostHandler filter list | |||
| flowPreHandlerFilters | Flow PostHandler filter list | |||
| flowPostHandlerFilters | Flow PostHandler filter list | |||
| runner | Flow runner | Default is single thread executor | ||
| properties | Flow properties | |||
| parseListeners | Flow parse listener list | |||
| logFlag | true/false, log flag |
'post' configuration
'post' has several configuration types as follows:
A、Fixed
1、{"to":XXX},to XXX node
B、Conditional
2、{"when":XXX, "to":XXX}
3、{"conditions":[{"when":XXX, "to":XXX},{"when":XXX, "to":XXX}]}
'when' is expression lanaguage
'conditionType' is optional: exclusive/inclusive,default is exclusive.
'defaultTo' is also optional.
C、Create expression.
4、{"createExp":XXX},execute when flow parsing. The result should be an implementation of NodePostHandler.
D、Expression
5、{"exp":XXX},execute when flow running
'to' configuration
String:If it starts with '$', it is an index: $first, $last, $previous or $next, or else it is a fix node id. Integer: Node index List:String list or Integer list Map: "exp":"XXX"
You can see configuration example in test folder.
SPEL expression variables.
Varialbles when flow running
| Name | Type | Description |
|---|---|---|
| context | FlowContext | Flow context |
| param | FlowParam | Flow param |
| bizParam | depend on invoker | param in FlowParam |
| paramData | Map | dataMap in FlowParam |
| result | FlowResult | Flow result |
| bizResult | depend on invoker | result in FlowResult |
| nodeContext | NodeContext | node context |
| actionResult | depend on implementation | Return value of NodeAction |
Other
Usage of filter and listener
Filer and listener all are pointcut control manner.
Exception process
By default, Flow engine don't catch or wrap exception, it throws original exception of business code.
Key naming conversion.
All keys of flow engine have no ':", The customize keys can start with 'XXX:' or ':'. 'XXX' is namespace.