Flow ServerStarter
流程控制

聚合

type aggregate

在设计器中打开 ↗

按 correlationKey 聚合,完成后执行子链

使用说明

要点:按 correlationKey 聚合,完成后执行子链。completion 至少需要 size / timeout / predicate 之一。

属性

字段类型必填默认值说明
aggregate
聚合表达式
表达式 必填 —
completion
完成条件
JSON 对象 必填 — {size, timeout, predicate} 至少一项
nodes
子节点
子链 可选 —
aggregationStrategy
聚合策略 Bean
文本 可选 —

示例流程

可直接保存为 demo-aggregate.json 并部署;非入口节点默认套了一个 REST 入口。

Flow JSON
{
  "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 的消息后触发聚合子链。

相关节点