With Spring Integration 2.0 we've added Groovy support allowing you to use Groovy scripting language to provide integration and business logic for various integration components similar to the way Spring Expression Language (SpEL) is use to implement routing, transformation and other integration concerns. For more information about Groovy please refer to Groovy documentation which you can find here: http://groovy.codehaus.org/
Depending on the complexity of your integration requirements Groovy scripts could be provided inline as CDATA in XML
configuration or as a reference to a file containing Groovy script.
To enable Groovy support Spring Integration defines
GroovyScriptExecutingMessageProcessor which will
create a groovy Binding object identifying Message Payload as
payload variable and Message Headers as
headers variable. All that is left for you to do is write script that uses these variables.
Below are couple of sample configurations:
<filter input-channel="referencedScriptInput"> <groovy:script location="some/path/to/groovy/file/GroovyFilterTests.groovy"/> </filter> <filter input-channel="inlineScriptInput"> <groovy:script><![CDATA[ return payload == 'good' ]]></groovy:script> </filter>
You see that script could be included inline or via
location attribute using the groovy namespace sport.
Other supported elements are router, service-activator, transformer, splitter
Another interesting aspect of using Groovy support is framework's ability to update (reload) scripts
without restarting the Application Context.
To accomplish this all you need is specify
refresh-check-delay attribute on script
element. The reason for this attribute is to make reloading of the script more efficient.
<groovy:script location="..." refresh-check-delay="5000"/>
In the above example for the next 5 seconds after you update the script you'll still be using the old script and after 5 seconds the context will be updated with the new script. This is a good example where 'near real time' is acceptable.
<groovy:script location="..." refresh-check-delay="0"/>
In the above example the context will be updated with the new script every time the script is modified. Basically this is the example of the 'real-time' and might not be the most efficient way.
<groovy:script location="..." refresh-check-delay="-1"/>
Any negative number value means the script will never be refreshed after initial initialization of application context. DEFAULT BEHAVIOR
|Inline defined script can not be reloaded.|