Multiple Messages
A function can return multiple messages on an output by returning an array of
messages within the returned array. When multiple messages are returned for an
output, subsequent nodes will receive the messages one at a time in the order they
were returned.
In the following example, msg1, msg2, msg3 will be sent to the first output. msg4 will be
sent to the second output.
var msg1 = { payload:"first out of output 1" };
var msg2 = { payload:"second out of output 1" };
var msg3 = { payload:"third out of output 1" };
var msg4 = { payload:"only message from output 2" };
return [ [ msg1, msg2, msg3 ], msg4 ];
The following example splits the received payload into individual words and returns a
message for each of the words.
var outputMsgs = [];
var words = [Link](" ");
for (var w in words) {
[Link]({payload:words[w]});
}
return [ outputMsgs ];
Working with sequences
There are a number of core nodes that can work across message sequences:
Split
Turns a single message into a sequence of messages.
The exact behaviour of the node depends on the type of [Link]:
String/Buffer
the message is split using the specified character (default: `\n`), buffer sequence or
into fixed lengths.
Array
the message is split into either individual array elements, or arrays of a fixed-length.
Object
a message is sent for each key/value pair of the object.
Join
Turns a sequence of messages into a single message.
The node provides three modes of operation:
Automatic
attempts to reverse the action of a previous Split node
Manual
allows finer control on how the sequence should be joined
Reduce
New in 0.18 - allows a JSONata expression to be run against each message in the
sequence and the result accumulated to produce a single message.
Sort
New in 0.18
Sorts the sequence based on a property value or JSONata expression result.
Batch
New in 0.18
Creates new sequences of messages from those received.
The node provides three modes of operation:
Number of messages
groups messages into sequences of a given length. The overlap option specifies how
many messages at the end of one sequence should be repeated at the start of the
next sequence.
Time interval
groups messages that arrive within the specified interval. If no messages arrive
within the interval, the node can optionally send on an empty message.
Concatenate Sequences
creates a message sequence by concatenating incoming sequences. Each sequence
must have a [Link] property to identify it. The node is configured with a list of
topic values to identify the order sequences are concatenated.