# Merging message streams

**URL:** https://discourse.nodered.org/t/merging-message-streams/62870
**Category:** General
**Tags:** function-node
**Created:** [20 May 2022 00:23 UTC](https://discourse.nodered.org/t/merging-message-streams/62870 "2022-05-20T00:23:11Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![tfuchs1987](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tfuchs1987/32/44508_2.png) [@tfuchs1987](https://discourse.nodered.org/u/tfuchs1987)
#### Post date: [20 May 2022 00:23 UTC](https://discourse.nodered.org/t/merging-message-streams/62870/1 "2022-05-20T00:23:11Z")

</div>

Hi Node-REDers,

I want to download several email attachments and send them inside one email. Everything works so far.

I just want to ask you guys what the best solution would be to merge or provide several message streams to a single email function-node.

At this time I am sending as much messages with "node.send(msg);" as I provide mail attachments and I merge the messages with a join-node. The problem here is if the last attchments sends the msg.complete earlier than the first messages completes, because it's super lage and needs a bit longer to download, it is lost and does not get caught by the join-node.

 ![temp](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/f/6f25b052316d0e1afbe7c8c6e852ffb1ac079a95.png)

You guys probably would do it in a smarter way. I am super happy about any advice and thanks in advance!

---

<div class="post-metadata">

### Author: ![tfuchs1987](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tfuchs1987/32/44508_2.png) [@tfuchs1987](https://discourse.nodered.org/u/tfuchs1987)
#### Post date: [20 May 2022 03:18 UTC](https://discourse.nodered.org/t/merging-message-streams/62870/2 "2022-05-20T03:18:17Z")

</div>

Ok the join-node needs to identify each message to be able to merge all messages in automatic mode. This even does not need a msg.complete. msg.parts.id and msg.topic just need to have a unique ID.

A simple example would be

```auto
//Send multiple messages and merge with a join-node
for (let i = 0 ; i<5; i++){
    msg.topc = msg._msgid;
    msg.parts = {
                    id: msg._msgid,
                    index: i,
                    count: 5,
    }
node.send(msg)
}

```

Fixed my problem but still, if you guys have a better, smarter solution please feel free to share

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [3 June 2022 03:18 UTC](https://discourse.nodered.org/t/merging-message-streams/62870/3 "2022-06-03T03:18:52Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
