规则文件格式
LiteFlow从2.5.0
版本开始支持3种配置方式
- xml
- json
- yml
本文档基本都是以xml的形式作示例,json和yml和xml配置起来都差不多,不会增加你额外的学习负担。只是形式不同而已
xml格式
在xml形式下的rule-source的配置方式如下:
本地文件:liteflow.rule-source=config/flow.xml
zk方式:liteflow.rule-source=xml:127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183
自定义配置源:liteflow.rule-source=xml:com.yomahub.liteflow.test.TestCustomParser
xml的完整形式举例:
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<nodes>
<node id="a" class="com.yomahub.liteflow.test.parser.cmp.ACmp"/>
<node id="b" class="com.yomahub.liteflow.test.parser.cmp.BCmp"/>
<node id="c" class="com.yomahub.liteflow.test.parser.cmp.CCmp"/>
<node id="d" class="com.yomahub.liteflow.test.parser.cmp.DCmp"/>
<node id="e" class="com.yomahub.liteflow.test.parser.cmp.ECmp"/>
<node id="f" class="com.yomahub.liteflow.test.parser.cmp.FCmp"/>
<node id="g" class="com.yomahub.liteflow.test.parser.cmp.GCmp"/>
</nodes>
<chain name="chain1">
<then value="a,c"/>
<when value="b,d,e(f|g)"/>
<then value="chain2"/>
</chain>
<chain name="chain2">
<then value="c,g,f"/>
</chain>
</flow>
json格式
在json形式下的rule-source的配置方式如下:
本地文件:liteflow.rule-source=config/flow.json
zk方式:liteflow.rule-source=json:127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183
自定义配置源:liteflow.rule-source=json:com.yomahub.liteflow.test.TestCustomParser
json的完整形式举例:
{
"flow": {
"nodes": {
"node": [
{
"id": "a",
"class": "com.yomahub.liteflow.test.parser.cmp.ACmp"
},
{
"id": "b",
"class": "com.yomahub.liteflow.test.parser.cmp.BCmp"
},
{
"id": "c",
"class": "com.yomahub.liteflow.test.parser.cmp.CCmp"
},
{
"id": "d",
"class": "com.yomahub.liteflow.test.parser.cmp.DCmp"
},
{
"id": "e",
"class": "com.yomahub.liteflow.test.parser.cmp.ECmp"
},
{
"id": "f",
"class": "com.yomahub.liteflow.test.parser.cmp.FCmp"
},
{
"id": "g",
"class": "com.yomahub.liteflow.test.parser.cmp.GCmp"
}
]
},
"chain": [
{
"name": "chain2",
"condition": [
{"type": "then", "value": "c,g,f"}
]
},
{
"name": "chain1",
"condition": [
{"type": "then", "value": "a,c"},
{"type": "when", "value": "b,d,e(f|g)"},
{"type": "then", "value": "chain2"}
]
}
]
}
}
yml格式
在yml形式下的rule-source的配置方式如下:
本地文件:liteflow.rule-source=config/flow.yml
zk方式:liteflow.rule-source=yml:127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183
自定义配置源:liteflow.rule-source=yml:com.yomahub.liteflow.test.TestCustomParser
yml的完整形式举例:
flow:
nodes:
node:
- id: a
class: com.yomahub.liteflow.test.parser.cmp.ACmp
- id: b
class: com.yomahub.liteflow.test.parser.cmp.BCmp
- id: c
class: com.yomahub.liteflow.test.parser.cmp.CCmp
- id: d
class: com.yomahub.liteflow.test.parser.cmp.DCmp
- id: e
class: com.yomahub.liteflow.test.parser.cmp.ECmp
- id: f
class: com.yomahub.liteflow.test.parser.cmp.FCmp
- id: g
class: com.yomahub.liteflow.test.parser.cmp.GCmp
chain:
- name: chain1
condition:
- type: then
value: 'a,c'
- type: when
value: 'b,d,e(f|g)'
- type: then
value: 'chain2'
- name: chain2
condition:
- type: then
value: 'c,g,f'