2. Groovy Component With Mule ESB
Groovy Component is very similar to python, ruby or java component.The Groovy
component provides developers with the facilities to integrate custom scripts into a
flow using the Groovy scripting engine.
As an example, you can write a custom script using Groovy language for an
application, save it in a separate file and then configure the Groovy component to
reference the file. Or, after placing the Groovy component on the Studio canvas you
can type in the script through the Groovy Pattern Properties pane.
3. Groovy Component With Mule ESB
Place the Groovy component in the message processor region from Mule palette.
4. Groovy Component With Mule ESB
Field Description
Display Name Unique name for groovy component in your mule
application.
ScriptText Type the script the component will load directly into this
space.
Script File Enter the location of the script to be loaded by the
component.The file can reside on the classpath or the
local file system.
5. Groovy Component With Mule ESB
UseAdvanced tab, to configure interceptors and property for Groovy component.
Interceptors enable the developer to provide additional services to the component
such as the ability to log transactions and the ability to log the time for each
transaction.
Configure these parameters to define attribute keys and their associated values.This
enables a component to quickly look up a value associated with a key.
7. Groovy Component With Mule ESB
Accessing flow variables in Groovy Component
a = message.getInvocationProperty('num1')
b = message.getInvocationProperty('num2')
sum=Integer.parseInt(a)+Integer.parseInt(b)
8. Groovy Component With Mule ESB
Setting property in the Groovy component. Go to Advanced tab and add property.
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd">
<flow name="sdfsffsdFlow">
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy">
<property key="num1" value="#[flowVars.a]"/>
<property key="num2" value="#[flowVars.b]"/><![CDATA[sum=Integer.parseInt(num1)+Integer.parseInt(num2)]]></scripting:script>
</scripting:component>
</flow>
</mule>