# Unexpected Join-node behaviour: Join got triggered N times by N message parts

**URL:** <https://discourse.nodered.org/t/unexpected-join-node-behaviour-join-got-triggered-n-times-by-n-message-parts/51415>\
**Category:** General\
**Created:** [23 September 2021 02:31 UTC](https://discourse.nodered.org/t/unexpected-join-node-behaviour-join-got-triggered-n-times-by-n-message-parts/51415 "2021-09-23T02:31:20Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![kakyoism](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kakyoism/32/46283_2.png) [@kakyoism](https://discourse.nodered.org/u/kakyoism)\
**Post date:** [23 September 2021 02:31 UTC](https://discourse.nodered.org/t/unexpected-join-node-behaviour-join-got-triggered-n-times-by-n-message-parts/51415/1 "2021-09-23T02:31:20Z")

</div>

I'm working on joining multiple inputs into a single trigger message.  
However, I noticed that the Join node gets triggered N times by the N message parts.  
Please see my test flow below

![Screen Shot 2021-09-23 at 10.24.31](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/3/23ca4361c1769be9fae9f6fd2959019edec716e2.png)

The Inject is configured this way:

![Screen Shot 2021-09-23 at 10.24.54](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/b/aba2141cdc912df0e027fe09a66952d1523e9586.png)

The Change nodes look like this:

![Screen Shot 2021-09-23 at 10.24.41](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/2/0235bd92a4ca7857e96ddadd1ed3205874d8f7a6.png)

![Screen Shot 2021-09-23 at 10.29.49](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/0/e0fd1756c5e7b23ab6412d6ce3453f670199f52f.png)

Now the Join node:

 ![Screen Shot 2021-09-23 at 10.25.04](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/1/f1fedb8bbf219a92d2a345974d5ae331e241fd52.png)

I expect the output to contain only one message on one Injection, but what I have got are two messages in sequence.

![Screen Shot 2021-09-23 at 10.29.33](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/f/efefc96cac5da4f12e9988c1c0de09bdbebff5aa.png)

What's wrong with my approach?

---

<div class="post-metadata">

**Author:** ![kakyoism](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kakyoism/32/46283_2.png) [@kakyoism](https://discourse.nodered.org/u/kakyoism)\
**Post date:** [23 September 2021 02:40 UTC](https://discourse.nodered.org/t/unexpected-join-node-behaviour-join-got-triggered-n-times-by-n-message-parts/51415/2 "2021-09-23T02:40:29Z")

</div>

## Further discovery

If I set the second Change to `set msg.payload to ...`, then the Join gets triggered only once.

## My guess

The config of Join `using the value of msg.topic as the key` actually means

_If the input messages of Join have different topics, we'll output these messages in sequence, because a single message can have only one topic._

Am I right?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 September 2021 06:34 UTC](https://discourse.nodered.org/t/unexpected-join-node-behaviour-join-got-triggered-n-times-by-n-message-parts/51415/3 "2021-09-23T06:34:12Z")

</div>

You have selected And every subsequent message, in the join node. So after two have been received then it sends a message out for every message it gets in.

---

<div class="post-metadata">

**Author:** ![kakyoism](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kakyoism/32/46283_2.png) [@kakyoism](https://discourse.nodered.org/u/kakyoism)\
**Post date:** [23 September 2021 06:36 UTC](https://discourse.nodered.org/t/unexpected-join-node-behaviour-join-got-triggered-n-times-by-n-message-parts/51415/4 "2021-09-23T06:36:30Z")

</div>

@Colin Thanks, Colin. But how would you explain my further discovery?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 September 2021 06:59 UTC](https://discourse.nodered.org/t/unexpected-join-node-behaviour-join-got-triggered-n-times-by-n-message-parts/51415/5 "2021-09-23T06:59:21Z")

</div>

Please export a flow showing the the problem and post it here. See this post for how to do that - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<div class="post-metadata">

**Author:** ![kakyoism](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kakyoism/32/46283_2.png) [@kakyoism](https://discourse.nodered.org/u/kakyoism)\
**Post date:** [23 September 2021 07:11 UTC](https://discourse.nodered.org/t/unexpected-join-node-behaviour-join-got-triggered-n-times-by-n-message-parts/51415/6 "2021-09-23T07:11:00Z")

</div>

@Colin Thanks for the pointer. Pretty new here and haven't figured out the canonical way to share code.

Here is the flow where the two branches trigger Join only once with `and every subsequent message` checked.

```auto
[
    {
        "id": "1233464d307d0b5d",
        "type": "tab",
        "label": "Flow 2",
        "disabled": false,
        "info": ""
    },
    {
        "id": "2d2bac86c2596d2a",
        "type": "inject",
        "z": "1233464d307d0b5d",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "src topic",
        "payload": "src payload",
        "payloadType": "str",
        "x": 140,
        "y": 260,
        "wires": [
            [
                "dbcd4dcc8463be89",
                "2228e402fba9335e"
            ]
        ]
    },
    {
        "id": "dbcd4dcc8463be89",
        "type": "change",
        "z": "1233464d307d0b5d",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 340,
        "y": 200,
        "wires": [
            [
                "0e33f1ccdbae667f"
            ]
        ]
    },
    {
        "id": "2228e402fba9335e",
        "type": "change",
        "z": "1233464d307d0b5d",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "topic",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 340,
        "y": 340,
        "wires": [
            [
                "0e33f1ccdbae667f"
            ]
        ]
    },
    {
        "id": "0e33f1ccdbae667f",
        "type": "join",
        "z": "1233464d307d0b5d",
        "name": "",
        "mode": "custom",
        "build": "object",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": true,
        "timeout": "",
        "count": "2",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "num",
        "reduceFixup": "",
        "x": 490,
        "y": 260,
        "wires": [
            [
                "9755c5d1a90b74b0"
            ]
        ]
    },
    {
        "id": "9755c5d1a90b74b0",
        "type": "debug",
        "z": "1233464d307d0b5d",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 610,
        "y": 260,
        "wires": []
    }
]

```

Please take a look.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 September 2021 07:53 UTC](https://discourse.nodered.org/t/unexpected-join-node-behaviour-join-got-triggered-n-times-by-n-message-parts/51415/7 "2021-09-23T07:53:12Z")

</div>

What erroneous behaviour does it show for you?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 September 2021 08:07 UTC](https://discourse.nodered.org/t/unexpected-join-node-behaviour-join-got-triggered-n-times-by-n-message-parts/51415/8 "2021-09-23T08:07:32Z")

</div>

For me, the very first time after I do a deploy it sends one message the first time I click the inject, and then two messages for every subsequent click, which is the correct behaviour.

---

<div class="post-metadata">

**Author:** ![kakyoism](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kakyoism/32/46283_2.png) [@kakyoism](https://discourse.nodered.org/u/kakyoism)\
**Post date:** [23 September 2021 09:40 UTC](https://discourse.nodered.org/t/unexpected-join-node-behaviour-join-got-triggered-n-times-by-n-message-parts/51415/9 "2021-09-23T09:40:08Z")

</div>

Ok, so `after a number of message parts` is actually meant for the very first trigger after the flow is loaded?

`every subsequent message` means every individual message arrived from any branch after the trigger from the first load-bang?

@Colin

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 September 2021 10:00 UTC](https://discourse.nodered.org/t/unexpected-join-node-behaviour-join-got-triggered-n-times-by-n-message-parts/51415/10 "2021-09-23T10:00:41Z")

</div>

Yes. If you only want a message every time two messages (with different topics) arrive then unset subsequent messages.
