Mattias Marder
unread,May 29, 2016, 4:16:21 PM5/29/16Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Node-RED
This question pops up frequently and I would like to propose an alternative flow that would avoid the risk of joining messages from separate sources.
The attached flow gives each incoming message an unique ID and the join node cares for checking that the 3 responses that it is waiting for all come from the same original message.
[{"id":"bdb52f32.3c0e4","type":"function","z":"d3334211.d1d0c8","name":"Wait for all tasks to finish","func":"QueryID = msg.ID;\ncontext.data = context.data || {};\ncontext.data[QueryID] = context.data[QueryID] || {task1 : null, task2: null, task3: null};\n\nswitch (msg.topic) {\n case \"task1\":\n context.data[QueryID].task1 = msg.payload;\n msg = null;\n break;\n case \"task2\":\n context.data[QueryID].task2 = msg.payload;\n msg = null;\n break;\n case \"task3\":\n context.data[QueryID].task3 = msg.payload;\n msg = null;\n break;\n \n default:\n msg = null;\n \tbreak;\n\n}\n\nif(context.data[QueryID].task1 !== null && context.data[QueryID].task2 !== null && context.data[QueryID].task3 !== null) {\n\tmsg2 = {};\n msg2 = context.data[QueryID];\n delete context.data[QueryID];\n\treturn msg2;\n} else return msg;","outputs":1,"noerr":0,"x":777,"y":1403,"wires":[["a2f95d9.d67ada"]]},{"id":"a501db75.5b02e","type":"delay","z":"d3334211.d1d0c8","name":"Random delay","pauseType":"random","timeout":"5","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":519,"y":1312,"wires":[["bdb52f32.3c0e4"]]},{"id":"a2f95d9.d67ada","type":"debug","z":"d3334211.d1d0c8","name":"","active":true,"console":"false","complete":"true","x":984,"y":1402,"wires":[]},{"id":"620c74c9.0b758c","type":"delay","z":"d3334211.d1d0c8","name":"Random delay","pauseType":"random","timeout":"5","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":523,"y":1408,"wires":[["bdb52f32.3c0e4"]]},{"id":"aabee8b4.2422d8","type":"delay","z":"d3334211.d1d0c8","name":"Random delay","pauseType":"random","timeout":"5","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":520,"y":1492,"wires":[["bdb52f32.3c0e4"]]},{"id":"166aae9.07a3651","type":"function","z":"d3334211.d1d0c8","name":"Task1","func":"msg.ID = msg.payload; //a unique ID given by the creator of this message.\nmsg.topic=\"task1\";\nmsg.payload=\"Task1's payload\"\nreturn msg;","outputs":1,"noerr":0,"x":351,"y":1312,"wires":[["a501db75.5b02e"]]},{"id":"3d8ee315.fafcdc","type":"function","z":"d3334211.d1d0c8","name":"Task2","func":"msg.ID = msg.payload; //a unique ID given by the creator of this message.\nmsg.topic=\"task2\";\nmsg.payload=\"Task2's payload\"\nreturn msg;","outputs":1,"noerr":0,"x":354,"y":1407,"wires":[["620c74c9.0b758c"]]},{"id":"f6e54c8e.12128","type":"function","z":"d3334211.d1d0c8","name":"Task3","func":"msg.ID = msg.payload; //a unique ID given by the creator of this message.\nmsg.topic=\"task3\";\nmsg.payload=\"Task3's payload\"\nreturn msg;","outputs":1,"noerr":0,"x":349,"y":1491,"wires":[["aabee8b4.2422d8"]]},{"id":"8db3e0ae.203a48","type":"inject","z":"d3334211.d1d0c8","name":"Start","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":185,"y":1396,"wires":[["166aae9.07a3651","3d8ee315.fafcdc","f6e54c8e.12128"]]}]