Loading...
The JavaScript batch adapter is an option common to almost all data types. When Process Batch is enabled on the Source Settings, you can set this script from the Set Data Types Window to programmatically decide how to split the incoming data into multiple messages.
Within the batch script you have access to a variable called "reader", which is a Java BufferedReader object. Use this variable to consume from the underlying character stream and return a String for each message you want to process through the channel. When you decide that no more messages should be processed, or you reach the end of the stream, return null or an empty string.
Example 1
return reader.readLine();
Example 2
var message = new java.lang.StringBuilder();
var line;
while ((line = reader.readLine()) != null) {
message.append(line).append('\r');
// Mark the stream for 3 characters while we check for MSH
reader.mark(3);
// Check for the code points corresponding to MSH
if (reader.read() == 77 && reader.read() == 83 && reader.read() == 72) {
reader.reset();
break;
}
reader.reset();
}
return message.toString();