|
|
Message Handling Script |
The Message Handling Script processor allows you to specify your own processor logic using JavaScript or Groovy, entered as an option for the processor.
The Message Handling Script processor is closely related to the Script processor. The main difference between this processor and the Script processor is that the Message Handling Script processor is designed to handle messages, which may contain many records. The Message Handling Script processor is capable of performing operations over all the records in a message, and has access to message level attributes such as the message ID.
Use the message handling script processor to define processing logic that acts across all the records in a message, or that acts selectively on only the first record in the message.
Any number of attributes of any type may be input to a Script processor. The input attributes are collated into a script array named input1. Each record in the message has its own instance of input1, containing the attribute values for that record.
|
Option |
Type |
Purpose |
Default Value |
|
|
Result type |
Selection (String / Number / Date / String Array / Number Array / Date Array) |
Determines the type of the output result of the script.
|
String |
|
|
Script |
Script |
The script defining the processor logic. See the Script section for more details. |
None |
The Message Handling Script processor supports a single output data attribute per record. The type of this attribute is determined by the setting of the Result type option.
The single output must be assigned to the script name output1.
|
Note:Selecting an Array type for your result type does not automatically instantiate the array. Due to the differences between simple data types and array types, the array must be instantiated by your script. Failure to do this will result in a script execution error when the processor is run. Please see Example 3 in the Script processor topic for more details. |
|
Data attribute |
Type |
Purpose |
Value |
|
ScriptResult |
Added |
An attribute with the result of the script. |
The value is set by the script. |
None
|
Execution Mode |
Supported |
|
Batch |
Yes |
|
Real-time Monitoring |
Yes |
|
Real-time Response |
Yes |
Note that when writing a new processor (which may include the use of script), it is possible to make the processor incompatible with Real-time Response execution, by flagging the processor as one which needs to run to completion (for example a processor that filters records based on a percentage calculated across all records that are processed).
The Message Handling Script processor presents no summary statistics on its processing.
In the Data view, each input attribute is shown with the output attributes to the right.
None
The following notes are important to consider when writing a script for the Message Handling Script processor.
The Message Handling Script processor takes a message as its unit of work. A message may be composed of multiple records, which are modeled as an array named records within the Message Handling Script processor. Each record in the array has its own set of input attributes and its own output attribute, corresponding to the input1 and output1 attributes of the standard Script processor.
In addition, a pre-defined variable, messageid, contains the unique message ID, and a variable tags, which contains the message level tags.
Each record also has a cancel() function, which suppresses further processing of the record in the process.
Note: It is possible to specify a function to be called for each record (as opposed to executing the entire script each time), and to change the language of the script.
To set a function include the line:
#! function : doit
at the top of the script (where 'doit' is the function name; change this to the function name you are using).
To change the language of the script to groovy rather than Javascript, add the line:
#! language : groovy
The following script will iterate across all the records in a message to calculate the sum of the values of the first input attribute for each record (which is assumed to be a number). It then iterates across the records a second time, and sets the value of the output attribute of each record to the sum calculated in the first step:
var sum = 0;
for (var i = 0; i < records.length; i++)
{
sum += records[i].input1[0];
}
for (var i = 0; i < records.length; i++)
{
records[i].output1 = sum;
}
The following script computes the sum as before, but all but the first record are suppressed using the cancel() function. This results in a single record - the first - being output per message, with the total of the first input attribute across all records as its output attribute.
var sum = 0;
for (var i = 0; i < records.length; i++)
{
sum += records[i].input1[0];
}
for (var i = 0; i < records.length; i++)
{
if (i == 0)
{
records[i].output1 = sum;
}
else
{
records[i].cancel();
}
}
Oracle ® Enterprise Data Quality Help version 9.0
Copyright ©
2006,2011 Oracle and/or its affiliates. All rights reserved.