0% found this document useful (0 votes)
48 views1 page

Multiple Messages: msg1 Payload msg2 Payload msg3 Payload msg4 Payload msg1 msg2 msg3 msg4

A function can return multiple messages by returning an array containing arrays of messages. Messages within the inner arrays will be sent to subsequent nodes sequentially on that output. In an example, a function returns an array with three messages on the first output and one message on the second output. Another example splits an input payload into individual words and returns each word in a separate message on the first output.

Uploaded by

rshegde
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views1 page

Multiple Messages: msg1 Payload msg2 Payload msg3 Payload msg4 Payload msg1 msg2 msg3 msg4

A function can return multiple messages by returning an array containing arrays of messages. Messages within the inner arrays will be sent to subsequent nodes sequentially on that output. In an example, a function returns an array with three messages on the first output and one message on the second output. Another example splits an input payload into individual words and returns each word in a separate message on the first output.

Uploaded by

rshegde
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

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 = msg.payload.split(" ");
for (var w in words) {
outputMsgs.push({payload:words[w]});
}
return [ outputMsgs ];

You might also like