规则文件格式

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的完整形式举例:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <flow>
  3. <nodes>
  4. <node id="a" class="com.yomahub.liteflow.test.parser.cmp.ACmp"/>
  5. <node id="b" class="com.yomahub.liteflow.test.parser.cmp.BCmp"/>
  6. <node id="c" class="com.yomahub.liteflow.test.parser.cmp.CCmp"/>
  7. <node id="d" class="com.yomahub.liteflow.test.parser.cmp.DCmp"/>
  8. <node id="e" class="com.yomahub.liteflow.test.parser.cmp.ECmp"/>
  9. <node id="f" class="com.yomahub.liteflow.test.parser.cmp.FCmp"/>
  10. <node id="g" class="com.yomahub.liteflow.test.parser.cmp.GCmp"/>
  11. </nodes>
  12. <chain name="chain1">
  13. <then value="a,c"/>
  14. <when value="b,d,e(f|g)"/>
  15. <then value="chain2"/>
  16. </chain>
  17. <chain name="chain2">
  18. <then value="c,g,f"/>
  19. </chain>
  20. </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的完整形式举例:

  1. {
  2. "flow": {
  3. "nodes": {
  4. "node": [
  5. {
  6. "id": "a",
  7. "class": "com.yomahub.liteflow.test.parser.cmp.ACmp"
  8. },
  9. {
  10. "id": "b",
  11. "class": "com.yomahub.liteflow.test.parser.cmp.BCmp"
  12. },
  13. {
  14. "id": "c",
  15. "class": "com.yomahub.liteflow.test.parser.cmp.CCmp"
  16. },
  17. {
  18. "id": "d",
  19. "class": "com.yomahub.liteflow.test.parser.cmp.DCmp"
  20. },
  21. {
  22. "id": "e",
  23. "class": "com.yomahub.liteflow.test.parser.cmp.ECmp"
  24. },
  25. {
  26. "id": "f",
  27. "class": "com.yomahub.liteflow.test.parser.cmp.FCmp"
  28. },
  29. {
  30. "id": "g",
  31. "class": "com.yomahub.liteflow.test.parser.cmp.GCmp"
  32. }
  33. ]
  34. },
  35. "chain": [
  36. {
  37. "name": "chain2",
  38. "condition": [
  39. {"type": "then", "value": "c,g,f"}
  40. ]
  41. },
  42. {
  43. "name": "chain1",
  44. "condition": [
  45. {"type": "then", "value": "a,c"},
  46. {"type": "when", "value": "b,d,e(f|g)"},
  47. {"type": "then", "value": "chain2"}
  48. ]
  49. }
  50. ]
  51. }
  52. }

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的完整形式举例:

  1. flow:
  2. nodes:
  3. node:
  4. - id: a
  5. class: com.yomahub.liteflow.test.parser.cmp.ACmp
  6. - id: b
  7. class: com.yomahub.liteflow.test.parser.cmp.BCmp
  8. - id: c
  9. class: com.yomahub.liteflow.test.parser.cmp.CCmp
  10. - id: d
  11. class: com.yomahub.liteflow.test.parser.cmp.DCmp
  12. - id: e
  13. class: com.yomahub.liteflow.test.parser.cmp.ECmp
  14. - id: f
  15. class: com.yomahub.liteflow.test.parser.cmp.FCmp
  16. - id: g
  17. class: com.yomahub.liteflow.test.parser.cmp.GCmp
  18. chain:
  19. - name: chain1
  20. condition:
  21. - type: then
  22. value: 'a,c'
  23. - type: when
  24. value: 'b,d,e(f|g)'
  25. - type: then
  26. value: 'chain2'
  27. - name: chain2
  28. condition:
  29. - type: then
  30. value: 'c,g,f'