-
Notifications
You must be signed in to change notification settings - Fork 8
Routes: Aggregator
The Simple Aggregator Route
The Simple Aggregator route node is the opposite of the branch route node. It will take incoming messages which match its dependencies and aggregate them into a single message.
The simple in the name implies that this node doesn't use any custom aggregation logic. It merely looks at the incoming message stream, picks out all the messages which match its dependencies, aggregates them one by one by combining their JSON properties, and when it has aggregated each of the messages listed in its dependencies, then it is done.
If the aggregation logic to be used is more complex than this, then it is recommended to use the JS route node instead.
The code block below documents the format for the Aggregation route node.
"route2":{
"type": "simple_aggregator",
"dependencies":[["route1.1"],["route1.2"]]
}
The only property that matters is dependencies
. It lists the incoming message labels which we must aggregate. The outgoing message will have the properties from all these messages combined into a single JSON object.
The code block below illustrates a simple message aggregation flow in a REST API.
{
"flow": {
"name":"Hello aggregation REST API",
"disabled": true
},
"listener": {
"type":"rest_listener",
"isMessageGenerator": true,
"port":9091,
"host":"127.0.0.1",
"url":"/hello"
},
"route0":{
"type": "branch",
"dependencies":"listener",
"outputs":["route0.1", "route0.2"]
},
"route1.1":{
"type": "js",
"dependencies":"route0.1",
"js":"message.content.response1 = `Hello ${message.content.name}`; delete message.content.name;"
},
"route1.2":{
"type": "js",
"dependencies":"route0.2",
"js":"message.content.response2 = `How are you doing, ${message.content.name}?`; delete message.content.name;"
},
"route2":{
"type": "simple_aggregator",
"dependencies":[["route1.1"],["route1.2"]]
},
"output": {
"type":"rest_responder",
"dependencies":["route2","!route1.1","!route1.2"]
}
}
(C) 2018 - 2021 TekMonks