The Fundamentals of Mule Configuration, Page 4
Configuration Settings
The knitting of service components into an application is done in a Mule configuration file. Mule configuration settings are the responsibility of the developer. They include:- The declaration of service components
- The endpoint(s) on which the service will receive messages
- Any transformers to use before presenting messages to a service component
- The outbound endpoint(s) where messages will go next
- Routing information for the message to dispatch it to the next service component
Declaring Service Components
<component class="org.my.ServiceComponentImpl"/>
<pooled-component class="org.my.ServiceComponentImpl"/>
<component>
<singleton-object class="org.my.ServiceComponentImpl"/>
</component>
<component class="org.my.PrototypeObjectWithMyLifecycle">
<entry-point-resolver-set>
<array-entry-point-resolver/>
<callable-entry-point-resolver/>
</entry-point-resolver-set>
</component>
<ejb:endpoint host="localhost" port="1099" object="SomeService" method="remoteMethod"/>
Configuring Endpoints
<file:endpoint name="fileReader" reverseOrder="true"
comparator="org.mule.transport.file.comparator.OlderFirstComparator"/> ...... <model> <service name="Priority1"> <file:inbound-endpoint ref="fileReader" path="/var/prio1"/> ...... </service> <service name="Priority2"> <file:inbound-endpoint ref="fileReader" path="/var/prio2"/> ...... </service> </model>
<inbound-endpoint address="udp://localhost:65432"/> <inbound-endpoint address="jms://test.queue"/>
<outbound-endpoint address="smtp://user:secret@smtp.host"/> <outbound-endpoint address="smtp://user:secret@smtp.host"/>
Configuring Inbound Routers
<inbound>
<selective-consumer-router>
<mulexml:jxpath-filter expression="msg/header/resultcode = 'success'"/>
</selective-consumer-router>
<forwarding-catch-all-strategy>
<jms:endpoint topic="error.topic"/>
</forwarding-catch-all-strategy>
</inbound>
<inbound>
<secure-hash-idempotent-receiver-router messageDigestAlgorithm="SHA26">
<simple-text-file-store directory="./idempotent"/>
</secure-hash-idempotent-receiver-router>
</inbound>
<inbound>
<secure-hash-idempotent-receiver-router messageDigestAlgorithm="SHA26">
<simple-text-file-store directory="./idempotent"/>
</secure-hash-idempotent-receiver-router>
</inbound>For an exhaustive list, refer to this link.
Configuring Outbound Routers
<outbound matchAll="true">
<filtering-router>
<endpoint address="jms://deposit.queue"/>
</filtering-router>
<filtering-router>
<jms:outbound-endpoint queue="large.deposit.queue"/>
<mulexml:jxpath-filter expression="deposit/amount >= 100000"/>
</filtering-router>
</outbound>
<outbound>
<pass-through-router>
<smtp:outbound-endpoint to="ross@muleumo.org"/>
</pass-through-router>
</outbound>
<outbound>
<static-recipient-list-router>
<payload-type-filter expectedType="javax.jms.Message"/>
<recipients>
<spring:value>jms://orders.queue</spring:value>
<spring:value>jms://tracking.queue</spring:value>
</recipients>
</static-recipient-list-router>
</outbound>For an exhaustive list, refer to this link.
Configuring a Transport/Connector
You can declare values equivalent to an endpoint URI to describe the connection information for the transport.<rmi:endpoint name="BadType" host="localhost" port="1099" object="MatchingUMO" method="reverseString"/> <jms:inbound-endpoint queue="test.queue"/> <ssl:endpoint name="clientEndpoint" host="localhost" port="60198" synchronous="true"/> <quartz:endpoint name="qEP6" repeatCount="10" repeatInterval="1000" jobName="job"/>Alternatively, you can define a connector configuration using the <connector> element. Mule uses standard components such as Work Manager for efficient pooling of thread resources and for more control over thread usage. For errors, you declare an exception strategy as well as transactional behavior.
<vm:connector name="VMConnector">
...
<default-connector-exception-strategy>
<vm:outbound-endpoint path="systemErrorHandler"/>
</default-connector-exception-strategy>
</vm:connector>
Configuring Transformers
You can configure a transformer locally or globally. A local transformer is defined on the endpoint where it is applied, while a global transformer is referenced when needed. The following code defines two global transformers (see definitions below).<xm:xml-to-object-transformer name="XMLToExceptionBean"
returnClass="org.mule.example.errorhandler.ExceptionBean"/> <custom-transformer name="ExceptionBeanToErrorMessage"
class="org.mule.example.errorhandler.ExceptionBeanToErrorMessage" returnClass="org.mule.example.errorhandler.ErrorMessage"/>
- <append-string-transformer> appends a string to an existing string.
<append-string-transformer name="myAppender" message=" ... that's good to know!"/>
- <xslt-transformer> processes a XML payload through XSLT.
<mulexml:xslt-transformer name="xslt" xslFile="./conf/xsl/cd-listing.xsl"> <mulexml:context-property key="title" value="#[header:ListTitle]"/> <mulexml:context-property key="rating" value="#[header:ListRating]"/> </mulexml:xslt-transformer>
Conclusion
This article has covered the basics of Mule and how to configure Mule components using XML. As well as being a platform for SOA, Mule also offers a SOA governance (registry/repository) facility called Mule Galaxy. It also supports administering and managing Mule deployments within an enterprise via Mule HQ.Acknowledgements
Thanks to Ron Gates for proofreading this article.
About the Author
Thribhuvan Thakur is a senior software engineer/Architect at Southwest Airlines with 14 years of experience in design and development. He has been working with Java since its inception, and with JMS since 1999. Thakur is a Sun Certified Java Programmer, Sun Certified Java Developer and Sun Certified J2EE Architect. He holds a Masters in Computer Science from the University of North Texas.
0 Comments (click to add your comment)
Networking Solutions
