流程控制
聚合
type aggregate
按 correlationKey 聚合,完成后执行子链
使用说明
要点:按 correlationKey 聚合,完成后执行子链。completion 至少需要 size / timeout / predicate 之一。
属性
| 字段 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
aggregate聚合表达式 |
表达式 | 必填 | — | |
completion完成条件 |
JSON 对象 | 必填 | — | {size, timeout, predicate} 至少一项 |
nodes子节点 |
子链 | 可选 | — | |
aggregationStrategy聚合策略 Bean |
文本 | 可选 | — |
示例流程
可直接保存为 demo-aggregate.json 并部署;非入口节点默认套了一个 REST 入口。
{
"id": "demo-aggregate",
"desc": "聚合 示例",
"group": "示例/流程控制",
"schemaVersion": 1,
"nodes": [
{
"id": "n1",
"type": "rest",
"props": {
"method": "POST",
"path": "/demo/aggregate",
"desc": "示例入口"
}
},
{
"type": "aggregate",
"props": {
"aggregate": {
"lang": "simple",
"script": "${header.group}"
},
"completion": {
"size": 3,
"timeout": 5000
},
"nodes": [
{
"type": "log",
"props": {
"message": "聚合完成:${body}",
"level": "INFO"
},
"id": "n2"
}
]
},
"id": "n1"
}
]
}
curl -X POST 'http://localhost:8086/flow' \
-H 'Content-Type: application/json' \
-H 'X-Flow-Token: change-me' \
--data-binary @demo-aggregate.json
调用方式
curl -X POST 'http://localhost:8086/demo/aggregate' \
-H 'Content-Type: application/json' \
-d '{}'
连续发送 3 条相同 Header group 的消息后触发聚合子链。