Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Groovy Component With Mule ESB

Groovy Component With Mule ESB

Groovy Component With Mule ESB

Jitendra Bafna

May 22, 2017
Tweet

More Decks by Jitendra Bafna

Other Decks in Technology

Transcript

  1. 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.
  2. Groovy Component With Mule ESB Place the Groovy component in

    the message processor region from Mule palette.
  3. Groovy Component With Mule ESB Field Description Display Name Unique

    name for groovy component in your mule application. Script Text 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.
  4. Groovy Component With Mule ESB Use Advanced 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.
  5. Groovy Component With Mule ESB Examples of Script Text <?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/beans http://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"><![CDATA[a=10 b=20 sum=Integer.parseInt(a)+Integer.parseInt(b)]]></scripting:script> </scripting:component> </flow> </mule>
  6. 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)
  7. 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/beans http://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>