Skip to main content

Create a Single Message From Separate Streams of Messages


You have messages arriving from different sources that you need to combine into a single message.

For example, you have three different sensors publishing values and you want to insert them into a database as a single entry.


Give each stream a unique msg.topic value and use the Join node to group them into a single message.





In the example flow, each Inject node represents a different source of messages. They each set a unique msg.topic value so they can be identified later in the flow.

The Join node has been configured in manual mode to create a key/value object using msg.topic as the key name. As we know there are three separate streams of messages to join, the node has been to configure to send on a message when it receives that number of parts.

This means it will send on a message each time it receives at least one message from three different topics - using the most recent value from each topic.

{    "temperature":10,    "humidity":0,    "pressure":999}

The node has further options to change its behaviour that have not been used in this recipe. For example, a timeout can be set to ensure it sends something in case one of the sensors stops sending values. If that is a concern, you may consider this recipe for providing a placeholder value.