Skip to content

Instantly share code, notes, and snippets.

@craftoid
Created June 7, 2020 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craftoid/d1882664c755b52a7565378c6dca3f18 to your computer and use it in GitHub Desktop.
Save craftoid/d1882664c755b52a7565378c6dca3f18 to your computer and use it in GitHub Desktop.
Join Sequence Recipe

control the order in which messages are joined.

Solution

Attach msg.parts to your messages to control the order in which they are auto-assembled by the join node...

Discussion

  • msg.parts.group must be identical for all parts
  • msg.parts.count is the number of packages that will be joined
  • msg.parts.index should be in {0 .. msg.parts.count - 1}

Note:

  • missing parts (missing index) will be replaced with null objects
  • duplicate parts (same index) will be overridden
[
{
"id": "b0d0bf45.3b9c6",
"type": "change",
"z": "8e046e9.da7d29",
"name": "parts.index = 1",
"rules": [
{
"t": "set",
"p": "parts.index",
"pt": "msg",
"to": "1",
"tot": "num"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 420,
"y": 220,
"wires": [
[
"66ee9fcf.ec9cc"
]
]
},
{
"id": "d1af64ea.236868",
"type": "join",
"z": "8e046e9.da7d29",
"name": "",
"mode": "auto",
"build": "string",
"property": "payload",
"propertyType": "msg",
"key": "topic",
"joiner": "\\n",
"joinerType": "str",
"accumulate": false,
"timeout": "",
"count": "",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "",
"reduceFixup": "",
"x": 910,
"y": 220,
"wires": [
[
"f148be71.f09278"
]
]
},
{
"id": "6ec1c3ab.008bd4",
"type": "change",
"z": "8e046e9.da7d29",
"name": "parts.index = 0",
"rules": [
{
"t": "set",
"p": "parts.index",
"pt": "msg",
"to": "0",
"tot": "num"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 420,
"y": 120,
"wires": [
[
"66ee9fcf.ec9cc"
]
]
},
{
"id": "a39825e3.e01b9",
"type": "change",
"z": "8e046e9.da7d29",
"name": "parts.index = 2",
"rules": [
{
"t": "set",
"p": "parts.index",
"pt": "msg",
"to": "2",
"tot": "num"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 420,
"y": 320,
"wires": [
[
"66ee9fcf.ec9cc"
]
]
},
{
"id": "f148be71.f09278",
"type": "debug",
"z": "8e046e9.da7d29",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 1070,
"y": 220,
"wires": []
},
{
"id": "66ee9fcf.ec9cc",
"type": "change",
"z": "8e046e9.da7d29",
"name": "group id and count",
"rules": [
{
"t": "set",
"p": "parts.id",
"pt": "msg",
"to": "mygroup",
"tot": "str"
},
{
"t": "set",
"p": "parts.count",
"pt": "msg",
"to": "3",
"tot": "num"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 730,
"y": 220,
"wires": [
[
"d1af64ea.236868"
]
]
},
{
"id": "2e221b1.51df8e4",
"type": "inject",
"z": "8e046e9.da7d29",
"name": "",
"topic": "",
"payload": "Mary",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 150,
"y": 100,
"wires": [
[
"6ec1c3ab.008bd4"
]
]
},
{
"id": "10bd8f79.53bee9",
"type": "inject",
"z": "8e046e9.da7d29",
"name": "",
"topic": "",
"payload": "Bob",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 150,
"y": 140,
"wires": [
[
"6ec1c3ab.008bd4"
]
]
},
{
"id": "1e097073.0d1fb",
"type": "inject",
"z": "8e046e9.da7d29",
"name": "",
"topic": "",
"payload": "likes",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 150,
"y": 200,
"wires": [
[
"b0d0bf45.3b9c6"
]
]
},
{
"id": "f4198579.6348b8",
"type": "inject",
"z": "8e046e9.da7d29",
"name": "",
"topic": "",
"payload": "hates",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 150,
"y": 240,
"wires": [
[
"b0d0bf45.3b9c6"
]
]
},
{
"id": "8e0e22e9.cfa61",
"type": "inject",
"z": "8e046e9.da7d29",
"name": "",
"topic": "",
"payload": "Summer",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 160,
"y": 300,
"wires": [
[
"a39825e3.e01b9"
]
]
},
{
"id": "93dfd24.5cc25b",
"type": "inject",
"z": "8e046e9.da7d29",
"name": "",
"topic": "",
"payload": "Winter",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 150,
"y": 340,
"wires": [
[
"a39825e3.e01b9"
]
]
}
]
@soenkegissel
Copy link

msg.parts.group is renamed to msg.parts.id

@soenkegissel
Copy link

msg.parts.index should NOT be in {0 .. msg.parts.count - 1}

It should be msg.parts.count WITHOUT minus 1.
As count = eg. 2 = 2 parts.
Index first time is 0, second time is 1 = two times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment