Batch node: unique batch id?

Hi There,

I am now playing around with the batch node and have a question to do with the IDs defined for batches. This question centres around the following flow which might be incorrect usage of the batch node:

[{"id":"61f1197fb98ebd3c","type":"group","z":"866410b56fa42447","name":"no parts attribute, batch generates batches that can be joined on","style":{"label":true},"nodes":["986e40576cf9935b","cc64390ba8e44396","73a7055de17cd629","974f6f2212ac282c","56cf09a7911cfe89","2a7824eca6408720","3d41c360d3045297","cf8a36a47aedbecb"],"x":206,"y":339,"w":1140,"h":409},{"id":"986e40576cf9935b","type":"inject","z":"866410b56fa42447","g":"61f1197fb98ebd3c","name":"","props":[{"p":"counter","v":"0","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":302,"y":693,"wires":[["cc64390ba8e44396"]]},{"id":"cc64390ba8e44396","type":"change","z":"866410b56fa42447","g":"61f1197fb98ebd3c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"counter","tot":"msg"},{"t":"set","p":"counter","pt":"msg","to":"$$.counter + 1","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":543,"y":577,"wires":[["73a7055de17cd629","974f6f2212ac282c"]]},{"id":"73a7055de17cd629","type":"batch","z":"866410b56fa42447","g":"61f1197fb98ebd3c","name":"","mode":"count","count":10,"overlap":0,"interval":10,"allowEmptySequence":false,"honourParts":false,"topics":[],"x":814,"y":577,"wires":[["56cf09a7911cfe89","2a7824eca6408720","cf8a36a47aedbecb"]]},{"id":"974f6f2212ac282c","type":"switch","z":"866410b56fa42447","g":"61f1197fb98ebd3c","name":"limit to 10_000 messages","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"10000","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":544,"y":380,"wires":[["cc64390ba8e44396"]]},{"id":"56cf09a7911cfe89","type":"debug","z":"866410b56fa42447","g":"61f1197fb98ebd3c","name":"debug 446","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"","statusType":"counter","x":1042,"y":466,"wires":[]},{"id":"2a7824eca6408720","type":"join","z":"866410b56fa42447","g":"61f1197fb98ebd3c","name":"","mode":"auto","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","useparts":false,"accumulate":"false","timeout":"","count":"","reduceRight":false,"x":1032,"y":577,"wires":[["3d41c360d3045297"]]},{"id":"3d41c360d3045297","type":"debug","z":"866410b56fa42447","g":"61f1197fb98ebd3c","name":"debug 450","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"","statusType":"counter","x":1230,"y":577,"wires":[]},{"id":"cf8a36a47aedbecb","type":"debug","z":"866410b56fa42447","g":"61f1197fb98ebd3c","name":"debug 451","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":true,"statusVal":"","statusType":"auto","x":1040,"y":707,"wires":[]}]

My question why is the batch id always the same for the batches generated by the batch node?

Shown is the last message in a batch followed by two messages of the next batch (indicated by the index value of 9, 0, and 1). That output is generated by the debug 451 node.

The id of all batches is the same as the original message id. The flow generates a single message that is updated with a counter so that in the end, ten thousand messages are generated that are batched into a thousand batches of ten - using the join node.

I would have assumed that the batches of ten would all be uniquely identified by a unique id (i.e. parts.id = parts.index == 0 ? RED.nodes.generateId() : currentBatchId instead of parts.id = msg._msgid)

Is this intended behaviour and if so, why? I would have assumed batches are unique and independent of the original messages that generated them.

Ok to answer my own question:

If the messages have unique message id (as in is the case if change node sets the _msgid), then the batches are assigned uniqued batch ids and in fact the _msgid of the first message - as suspected.

(Message id is faked here and generated using $formatBase($random() * 1000000000, 16))

So I was generating an incorrect usage of the batch node by using the same _msgid for all messages.

1 Like