Mule's configuration is based on Spring and uses XML schemas to provide code completion. This makes it very easy to write your integration flows. Let's start with a very basic Mule configuration:
<mule xmlns="http://www.mulesource.org/
schema/mule/core/2.1" xmlns:xsi="http://www.
w3.org/2001/XMLSchema-instance" xmlns:vm="http://
www.mulesource.org/schema/mule/vm/2.1" xmlns:file="http://www.mulesource.org/schema/mule/file/2.1"
xsi:schemaLocation="
http://www.mulesource.org/schema/mule/core/2.1
http://www.mulesource.org/schema/mule/core/2.1/mule.xsd
http://www.mulesource.org/schema/mule/vm/2.1
http://www.mulesource.org/schema/mule/vm/2.1/mule-vm.xsd
http://www.mulesource.org/schema/mule/file/2.1
http://www.mulesource.org/schema/mule/file/2.1/mule-file.xsd">
<model name="refcheat-model">
<service name="basic-service">
<
inbound>
<file:inbound-endpoint name="example-in"
path="work/example/in" />
</inbound>
<component>
<singleton-object class="dzone.Reverser" />
</component>
<outbound>
<pass-through-router>
<file:outbound-endpoint name="example-out"
Configuring Mule, Continued
path="work/example/out" />
</pass-through-router>
</outbound>
</service>
</model>
</mule>
You can see that at the top of the file we've declared a number of Mule specific namespaces. Mule provides XML schemas for all its features. We'll focus on Mule core sheets, but also show you a couple of features from the vm and file schemas. After the namespaces declaration we define a <model> element. A model in Mule is a container element for a number of services. In the model element you can see that we've defined a single service where the parts we've discussed in the introduction appear again. In this case we've configured a file transport which will read messages from the file system, pass it on to a component which will reverse the content of the input file, and finally use an outbound router, with a single transport to write the now reversed string back to the file system. We didn't specify an inbound-router. If we don't specify one, all the messages are simply processed by the specified component.
In this example the inbound endpoint uses the File transport. Mule provides several standard transports you can use, as described in the next section. For details on a specific transport, see http://www.mulesource.org/display/MULE2USER/Available+Transports
We won't go into the details of all the endpoints. We'll just provide an overview of the transports available.
Mule Transports
Here is an overview of the transports Mule provides.
Namespace |
Description |
file |
Provides endpoints which allow you to read and write to the file system |
axis |
Allows you to consume and provide webservices using axis |
jbpm |
Adds functionality to interact with jBPM |
cxf |
Allows you to consume and provide webservices using CXF |
ejb |
Using the endpoints from this transport you can connect to EJBs |
email |
The email namespace provides functionality to connect to POP3, SMTP and IMAP servers |
ftp |
Provides endpoints to read and write to ftp servers |
http |
Allows you to receive and send information using HTTP |
jdbc |
With the JDBC endpoints you can interact with databases using SQL |
jms |
Provides endpoints to connect to JMS queues and topics |
multicast |
Provides an UDP multicast endpoint |
quartz |
Allows you to control the quartz job manager from Mule |
rmi |
Provides inbound and outbound endpoints for RMI |
stdio |
Allows you to send messages to mule using stdio |
tcp |
Provides endpoints for tcp connectivity |
udp |
Provides endpoints for udp connectivity |
vm |
The vm endpoint can be used for internal communication |
xmpp |
The XMPP endpoint can be used to connect to XMPP compliant instant messaging servers |
Mule Expressions
With expressions Mule allows you to access certain properties from the message or from the payload, and based on these
Mule Expressions, Continued
properties, execute certain actions. There are, for instance, routers, filters, and transformers that work based on these expressions. Below are a couple of examples of how these expressions can be configured. The first one shows how to use an expression on a filter.
<expression-filter evaluator="header" expression="priority=1"/>
This one shows how you can use expressions for routing.
<expression-recipient-list-router
evaluator="xpath"
expression="/header/routing/recipient" />
Available Evaluators
To use an expression, you specify an evaluator (the expression type) and the expression itself.
Evaluator |
Description |
attachment |
Allows you to access an attachment of a message |
attachments |
Returns a java.util.Map of attachments |
attachments-list |
Returns a java.util.List of attachments objects |
bean |
With this property you can access the message using a javabean style |
endpoint |
Allows you to access endpoint information |
exception-type |
Allows you to match the type of an exception |
function |
Performs a function: now, date, datestamp, systime, uuid, hostname, ip, or count. Not supported by expression filters. |
groovy |
Evaluates the expression using the Groovy language |
header |
Evaluates the specified part of the message header |
headers |
Returns all the headers as a java.util.Map |
headers-list |
Returns all the headers as a java.util.List of header values |
jxpath |
Allows you to specify an XPath expression that works on XML and javabeans |
map-payload |
Returns a single value from a Map |
message |
Gives you access to various message properties: id, correlationId, correlationSequence, correlationGroupSize, replyTo, payload, encoding, exception |
mule |
Allows access to certain Mule properties: serviceName, modelName, inboundEndpoint, serverId, clusterId, domainId, workingDir and homeDir |
ognl |
Allows you to use OGNL to access the message |
payload |
If expression is provided, it will be a class to be class loaded. The class will be the desired return type of the payload. |
payload-type |
Allows you to check the payload-type of the message |
regex |
Allows you to use a regular expression to access data |
wildcard |
You can use a wildcard expression to determine whether a filter matches |
xpath |
Allows you to use an XPath expression |
Most elements allow you to configure the expression using the evaluator and expression attributes. For properties, you can specify multiple expressions using #[<evaluator>:<expression>] in Mule 2.1 or ${<evaluator>:<expression>} in Mule 2.0. For example: <message-properties-transformer> <add-property name="GUID" value="#[xpath:/msg/header/ID]-#[xpath:/msg/body/@ref]"/> </message-properties-transformer> For more information on expressions you can look at http://www.mulesource.org/display/MULE2USER/Expressions+Configuration+Reference.
{{ parent.title || parent.header.title}}
{{ parent.tldr }}
{{ parent.linkDescription }}
{{ parent.urlSource.name }}