I want to divide one flow into two parallel flows, and then when both flows are finished i want to join them back into one, while also merging one object(msg.data in my case) in wich I store relevant info to be used after the flows are joined into one.
This is what Ive tried so far (Im trying achieve this with a join node, but I welcome any other solutions):
[
{
"id": "a55f9253.62fd6",
"type": "inject",
"z": "759de691.424df8",
"name": "msg.data = { }",
"props": [
{
"p": "data",
"v": "{}",
"vt": "json"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 2350,
"y": 140,
"wires": [
[
"43f34c27.69f9b4",
"59fe93e0.950a4c"
]
]
},
{
"id": "43f34c27.69f9b4",
"type": "function",
"z": "759de691.424df8",
"name": "function1",
"func": "msg.data.a = \"a\";\nmsg.data.b = \"b\";\nmsg.data.c = \"c\";\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 2540,
"y": 120,
"wires": [
[
"8df7d6bf.2dc188"
]
]
},
{
"id": "59fe93e0.950a4c",
"type": "function",
"z": "759de691.424df8",
"name": "function2",
"func": "msg.data.d = \"d\";\nmsg.data.e = \"e\";\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 2540,
"y": 160,
"wires": [
[
"8df7d6bf.2dc188"
]
]
},
{
"id": "8df7d6bf.2dc188",
"type": "join",
"z": "759de691.424df8",
"name": "",
"mode": "custom",
"build": "merged",
"property": "data",
"propertyType": "msg",
"key": "topic",
"joiner": "\\n",
"joinerType": "str",
"accumulate": true,
"timeout": "",
"count": "2",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "num",
"reduceFixup": "",
"x": 2710,
"y": 140,
"wires": [
[
"71e14cc6.03b514"
]
]
},
{
"id": "71e14cc6.03b514",
"type": "debug",
"z": "759de691.424df8",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 2850,
"y": 140,
"wires": []
}
]
First I create an inject node and I set msg.data to an empty json inside of it.
Then I divide the flow like this:
In function1 I have:
msg.data.a = "a";
msg.data.b = "b";
msg.data.c = "c";
return msg;
In function2 I have:
msg.data.d = "d";
msg.data.e = "e";
return msg;
After this Im atempting to join both flows into one, and to merge the msg.data to look like this:
msg.data = {
"a": "a",
"b": "b",
"c": "c",
"d": "d",
"e": "e"
};
My join node looks like this:
I set the node to set the msg 'After a number of message parts' = 2, since I have 2 separate parallel flows.
And this is the result I get in the debugs:
What I would want is to have only one response in the debugs instead of two(meaning the parallel flows have reunited back into one), with msg.data having a,b,c,d and e, like I have in the second debug.
I suspect this 2 in the join node indicates the number of properties inside my msg.data object(5 in this example) and not the times that msg.data is returned(wich would be 2, one per parallel flow). Important note: I dont know how many fields will msg.data have in my real scenario.
Any suggestions on how to accomplish this with or without a join node would be appreciated.
Thanks.