JavaScript Batch Script
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
This script will simply send a message for every line in the input.
return reader.readLine();
Example 2
This script will split the input into multiple messages by assuming that each new message starts with a line break and the characters "MSH". Note that this is already a feature supported by the , but is shown here to illustrate how the batch script can be used.
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();