sequence
Last updated
Last updated
This component splits a payload to separate messages.
In this example, we create three types of input and the split component separates each msg.payload to messages.
You may set up properties for all types of payload, the component will use them according to the input.
String/Buffer
Split using (1) - choose the type the splitter: string (default "\n"), buffer, or Fixed length of (will split on messages of specified length).
Handle as a stream of messages (2) - in this mode, the component will hold the last incomplete part of the message (in our instance str3 has no the / splitter) and add it in front of the first part of the next one. So all the incoming messages are considered as one stream and split when the divider comes, and, for example, three msg.payloads 'Hello, ', 'world!', and '/' will be merged to Hello, world! with the split component (if Split using the / splitter)!
Array
Split using (3) - specify the fixed number of arrays elements of each output payload.
But if the last part of the array has fewer elements than this number, it still will be sent. For example, the split component with Fixed length of 2 will split the array [1, 2, 3] to [1, 2] and [3].
Object
Copy key to (4) - when splitting an object the component returns only values of its properties in msg.payloads. You can specify an msg property to show the keys of values. (These keys are also sent in the parts property object - see below).
Note: the component also adds parts property with details of splitting to the output message (see the component's Help). This property is used by the join component to merge messages. (See below).
The opposite to the previous component. It merges messages into one payload. There are three modes of component's properties.
automated mode
In this mode, the component joins inputs using the msg.parts property that is made by the split component. For the instance, we took the split flow and checked if there the parts property. Then we checked the merged message of the join component.
2. manual
Combine each (1) - specify the msg property for the merger (msg.payload by default).
to create (2) - choose the resulting payload type: a String, a Buffer, an Array, a key/value Object, or a merged Object.
If you choose a key/value Object you will be prompted to specify the msg property which value will be used as the key. By default, it's msg.topic so the resulting object will have values of msg.topic: msg.payload.
joined using (3) - specify the joining characters. By default, it's \n (it will not be reflected in the message, but this notion means that each part of the message will be in a new line). If the field is empty, the messages will be merged without any dividers: 'Hello' and 'world' will be combined to 'Helloworld'.
Send the message:
After a number of message parts (4) - if you put 2 in the field, every two messages will be merged and sent. And so on.
After a timeout following the first message (5) - specify in seconds how often the merged message will be sent. All the messages that arrived in each time span will be combined. It has to be at least one message to make an output.
After a message with the msg.complete property set (6) - not an option. A message with this property will trigger the join component output (even if it is not completed due to other settings).
3. reduce sequence
For this mode, the incoming messages must have the msg.parts property (for example, made by the split component) - that means the output message will be sent only when all parts have arrived (in our example, the split component divided the message to three parts).
Reduce exp (1) - a JSONata expression that is executed with each incoming message. The result is passed to the next call of the expression as the accumulated value (read the join component Help). Click three dots to open the JSONata expression editor and select wanted functions. In the Test tap of this editor, you will be able to test the expression result.
Initial value (2) - set up the initial value ($A in JSONata expressions)
Fix-up exp (3) - the expression that will be called on the result of Reduce exp call on each message.
Learn more about JSONata expression in the component Help.
This component sorts incoming message elements or messages sequence using a specified key.
For example, you can put in order the messages from various sensors. Or create a new sorted array message from an array of raw data.
In this example, we first check the split component output: three strings of the initial array. Then we sort these messages sequence as strings and then as numbers (but the output messages are still strings).
Sort (1) - choose what to sort: a message property (msg.payload by default) or a sequence of messages.
Key (2) - choose the key for sorting.
For a message property, the key may be an element value or JSONata expression. For example, the array [154,3,12]
will give the [3,12,154]
output array (in ascending order).
For a message sequence, the key may be a message property (for example, msg.payload as in our instance) or JSONata expression.
The component requires the msg.parts property to determine the bunch of messages to sort (this property is created automatically by the split component, or you can specify it manually - see the property object structure in the component Help).
Order (3) - you can sort in ascending or descending order.
(4) - also the component can consider the data as numbers (if possible). In our example, we sorted string messages as numbers.
The component creates sequences of messages in three modes. The component collects messages while 'waits' a specified condition, and then sends a batch of outputs at a time.
Group by number of messages mode (1)
Specify the Number of messages to make a batch (2).
Select Overlap (3). You can order the component to use the defined number of last elements of one batch to be used as the first elements of the next batch.
Group by time interval mode
Choose the interval for sending sequences of messages. The component can send an empty message if there is no incoming data during the interval.
Concatenate messages mode
Add the msg.topic properties of incoming messages to make a sequence.
Note: each incoming message must have msg.parts property to identify its sequence.