Comment on page
Scripting
Joule provides a flexible and extendable model of component development which includes executing external scripts or defined expression within the use case DSL.
Currently only Javascript is supported with additonal languages being added with respect to roadmap commitments.
The below Javascript expression calculations the total compensation using StreamEvent fields which are passed in to the processing context.
scripting:
expression: salary + bonus + pensionContribution
expand all: true
Attribute | Description | Data Type | Required |
---|---|---|---|
expression | Expression to evaluate against the passed event | String | |
script | Name and location of script to be used | String | |
method | Method to call within script | String Default: processEvent | |
response attribute | Name of attribute to be used when adding the result in to the StreamEvent object. If the processor is set as stateful this value is also added to the processing context. | String Default: result | |
response datatype | Response data type returned from either the expressoin or script method. Supported data types: DOUBLE, FLOAT, LONG, INTEGER, SHORT, BYTE, BOOLEAN, STRING | String Default: DOUBLE | |
expand all | Expand all StreamEvent attributes within the scripting process context to enable access | Boolean Default: | |
stateful | Cache and reuse the response attribute for further processing. | Boolean Default: false |
The processor can also load external javascript script which may have complex set of functions that can be leveraged.
The below DSL definition will load
totalCompensationCalc.js
file in to the scripting engine, execute the totalCompensationCalc
with the result as totalCompensation
being added to the the StreamEvent object.scripting:
method: totalCompensationCalc
response attribute: totalCompensation
script: /var/joule/scripts/totalCompensationCalc.js
Simple example which demostrates the key capability.
function totalCompensationCalc(){
return salary + bonus + pensionContribution;
}
The following languages are supported using external file execution. Currently only a single langauge is supported, however there is work underway to extend this to more languages.
- Javascript
Last modified 10mo ago