Hi there,
The following flow is a filter and collect flow - I have 10 things, I want 5 buckets of 2 - how do I do this?
Using the split node, I can divide by 10 things into ten times 1 thing, then using switch, I can identify my buckets and using join, I can collect the things into my buckets. Each join is then one bucket.
But each join is awaiting all parts from the split node, so they never send a message with their collected things. No I can't count and tell the join to send a message after 2 things because I don't know how large the bucket will become.
So my solution has been to use another join that does collect all things and once it sends a message (i.e. it has received all things), a delay of 1 second is used and a final complete message is sent to all other joins. And with that I have my buckets sending out their collected things.
My request was to be: could the split node send a complete message once all items have been split but that would raise the question of message ordering and delays. I.e. an extra option on the split node: "send complete after X seconds" would be what I'm doing here and that's a hack already since the delay is assuming that all messages have been sent to the join nodes - that might not be the case.
Can a join node assume that it has received all messages if a parts labelled { index: 8, length: 9 } is received? No it can't, there being no guaranteed ordering of messages.
So the "true" solution would be to filter the things using a large array inside a function node but that's not "visual" flow code for me ![]()
(This example flow is take layers from an image and splitting those layers into 4 json files to be used elsewhere - so one file containing multiple layers - that also overlap - becomes 4 files.)
[{"id":"fdcf5d2989a1bc3f","type":"split","z":"eb2518b78d92c110","name":"split on layers","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","property":"payload.payload.layers","x":104,"y":368,"wires":[["61b8db53fc7da012","287989e94c61e33f"]]},{"id":"61b8db53fc7da012","type":"switch","z":"eb2518b78d92c110","name":"filter layers","property":"payload.payload.layers.name","propertyType":"msg","rules":[{"t":"regex","v":"^filter1","vt":"str","case":true},{"t":"regex","v":"^filter2","vt":"str","case":true},{"t":"regex","v":"^filter3","vt":"str","case":true},{"t":"regex","v":"^layer1","vt":"str","case":true},{"t":"regex","v":"^layer2","vt":"str","case":true},{"t":"regex","v":"^layer3","vt":"str","case":true},{"t":"regex","v":"^layer4","vt":"str","case":true}],"checkall":"false","repair":false,"outputs":7,"x":405,"y":368,"wires":[["02507f416cb8c956"],["6ed9721bec8407d0"],["bb36069257f3d9c2"],["04cd59b10eddb46a"],["c646e02acedb6cd8"],["c646e02acedb6cd8"],["c646e02acedb6cd8"]]},{"id":"02507f416cb8c956","type":"join","z":"eb2518b78d92c110","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","useparts":false,"accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1171,"y":129.25,"wires":[[]]},{"id":"6ed9721bec8407d0","type":"join","z":"eb2518b78d92c110","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","useparts":false,"accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1171,"y":253.25,"wires":[[]]},{"id":"bb36069257f3d9c2","type":"join","z":"eb2518b78d92c110","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","useparts":false,"accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1171,"y":372,"wires":[[]]},{"id":"04cd59b10eddb46a","type":"join","z":"eb2518b78d92c110","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","useparts":false,"accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1171,"y":541,"wires":[[]]},{"id":"c646e02acedb6cd8","type":"change","z":"eb2518b78d92c110","name":"mark as overlay layer","rules":[{"t":"set","p":"payload.component","pt":"msg","to":"overlay","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":540,"wires":[["5ce548081b392fe0"]]},{"id":"5ce548081b392fe0","type":"junction","z":"eb2518b78d92c110","x":916.998779296875,"y":540.6844395399094,"wires":[["02507f416cb8c956","6ed9721bec8407d0","bb36069257f3d9c2","04cd59b10eddb46a"]]},{"id":"287800d7f6075fc5","type":"group","z":"eb2518b78d92c110","name":"signal to the colletors that everything has been seen","style":{"label":true},"nodes":["287989e94c61e33f","a046cdac74882720","7f7d2c3a7f8eedce"],"x":548,"y":702,"w":344,"h":129},{"id":"287989e94c61e33f","type":"join","z":"eb2518b78d92c110","g":"287800d7f6075fc5","name":"","mode":"auto","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","useparts":false,"accumulate":true,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":624,"y":774,"wires":[["a046cdac74882720"]]},{"id":"a046cdac74882720","type":"change","z":"eb2518b78d92c110","g":"287800d7f6075fc5","name":"","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"complete","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":771,"y":743,"wires":[["7f7d2c3a7f8eedce"]]},{"id":"7f7d2c3a7f8eedce","type":"delay","z":"eb2518b78d92c110","g":"287800d7f6075fc5","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":806,"y":790,"wires":[["5ce548081b392fe0"]]}]