Mule : Groovy Support
This page last changed on May 31, 2006 by tcarlson.
Groovy ComponentsGroovy scripts can be invoked as Mule managed components by using org.mule.extras.groovy.GroovyComponent. <mule-descriptor name="GroovyUMO" inboundEndpoint="jms://localhost/groovy.queue" implementation="org.mule.extras.groovy.GroovyComponent"> <properties> <property name="script" value="test1.groovy"/> <property name="methodName" value="receive"/> <property name="autoReload" value="true"/> <property name="reloadInterval" value="60000"/> </properties> </mule-descriptor>
Groovy Configuration BuilderThe GroovyConfigurationBuilder allows developers to create a mule instance from a groovy script. To load the manager from a script for code - GroovyConfigurationBuilder builder = new GroovyConfigurationBuilder(); UMOManager manager = builder.configure("../conf/mule-config.groovy"); Or to start the server from the command line - java -cp ... org.mule.MuleServer -builder org.mule.extras.groovy.config.GroovyConfigurationBuilder -config ../conf/mule-config.groovy For more information about configuring a Mule instance from code or script see Configuring Mule Programmatically. Groovy TransformersGroovy support currently provides transformers to enable Mule users to transform events using groovy scripts. class StringListTransformer { toList(src) { return src.toString().tokenize(","); } toString(src) { result=""; src.each { t | result+= "," + t }; return result.substring(1); } } the configuration for the transformer would look like - <transformer name="StringToList" className="org.mule.extras.groovy.GroovyTransformer" returnClass="java.util.List"> <properties> <property name="sourceType" value="java.lang.String"/> <property name="script" value="./groovy/StringListTransformer.groovy"/> <property name="methodName" value="toList"/> </properties> </transformer> The sourceType property tells the transformer only to accept source objects of type string. This property can be set multiple times to register different source types. The methodName property specifies which method to call on the script. The default is 'transform'. The script property specifies the location and name of the script. If this value is not set, it will default to the name of the the transformer with the groovy extension. So to simplify configuration you may want to have one groovy script per transform with a single method called transform. |
![]() |
Document generated by Confluence on Oct 03, 2006 09:23 |