Mule Framework Guideline
Mule Framework Guideline
Mule Framework Guideline
1
1 2009
Table of Contents
1.1. Introduction 4
1.2. Installation 5
1.2.1. Prerequisites 5
1.2.2. Download 5
2
1 2009
Abbreviation
UMO = Universal Message Object
ESB = Enterprise Service Buss
3
1 2009
1.1. Introduction
Mule is a light-weight messaging framework. It is a highly distributable object broker that can seamlessly handle
interactions with other applications using disparate technologies, transports and protocols.
The Mule framework provides a highly scalable environment in which you can deploy your business components.
Mule manages all the interactions between components transparently whether they exist in the same VM or over the
internet and regardless of the underlying transport used.
Mule was designed around the Enterprise Service Bus architecture, which stipulates that different components or
applications communicate through a common messaging bus, usually implemented using Jms or some other
messaging server.
Mule architecture is scalable, highly distributable object broker that can seamlessly handle interactions across legacy
systems, in-house application and almost all modern transports and protocols. Mule is feature rich & easy to deploy.
The diagram below shows a common scenario with Mule. Mule applications usually consist of many Mule instances
across the network. Each instance is a light-weight container that hosts one or more UMO component. Each UMO
component will have one or more endpoints that it will send and receive events through.
4
1 2009
1.2. Installation
1.2.1. Prerequisites
Following are the prerequisites you must meet before you can install Mule.
• Java Developer Kit (JDK) 1.4x or greater is required for deploying Mule. JDK 1.5.x is required for building Mule
from the source code. Download.
• The JAVA_HOME environment variable must be set to the directory where the JDK is installed, e.g.
C:\java\j2sdk1.4.2_08
• Your path environment variable must contain the path to the JDK bin directory, such as
C:\java\j2sdk1.4.2_08\bin.
• Ant 1.7.0 is required to build from source code & running some examples.
• Maven 1.0.2 is required for building from the source code and running some of the examples. Download.
• A compression tool such as WinZip (Windows) or GZip (Linux/Unix) is required for decompressing the Mule
distribution of the community edition, snapshot release, or source code.
• For Linux/Unix users working from a shell, a download tool such as wget or _ftp _is required for downloading
the Mule distribution.
1.2.2. Download
Latest editions of mule are available at the following link. Download the full distribution of Mule2.0. Downloading
mule will take good amount of time so start downloading go to grab a cup of tea.
http://mule.mulesource.org/display/MULE/Download
5
1 2009
Distribution contents
The Mule distribution contains the following directories:
• /bin - Shell and batch scripts for controlling Mule from the command line
• /conf - Configuration files
• /docs - API documentation (Javadoc) for Mule and its sub-projects (not included in the Developer releases)
• /examples - Example applications you can run and try building yourself (not included in the source
distribution)
• /lib/boot - Libraries used by the Java Service Wrapper to boot the server
• /lib/mule - Core Mule libraries
• /lib/opt - Third-party libraries
• /lib/user - Your custom classes and libraries. This directory comes before
/lib/mule on the classpath and can therefore be used to patch the distributed Mule classes if necessary. If
you add files to this directory when Mule is already running, you must restart Mule after adding the files.
• /licenses - License information for all libraries shipped with Mule
• /logs - Log file output when running in background mode
• /sbin - Internal scripts (not to be run by the user)
• /src - The source code for all Mule modules. You can import this into your IDE.
• /LICENSE.txt - License agreement for Mule.
Download mail-1.4.jar from the following link & put it in <MULE_HOME>/lib/boot directory.
http://repo1.maven.org/maven2/javax/mail/mail/1.4/mail-1.4.jar
Note: Mule includes connectors for a wide variety of technologies. Some connectors use libraries that cannot be
distributed as part of Mule because of licensing restrictions. For these connectors, you must obtain the required
libraries and place them in the MULE_HOME/lib/user directory.
6
1 2009
Before you can use Mule, you must create the MULE_HOME environment variable and set it to the location of your
Mule installation. You must also add the location of your MULE_HOME/bin directory to your path.
Eg.
set MULE_HOME=C:\Mule
set PATH=%PATH%;%MULE_HOME%\bin
7
1 2009
Mule configuration file contains information about UMO services & their endpoints. Basic tree structure of the
configuration file is as follow. But there are many more tags. Root of the tree is always being mule tag.
<mule>
<model name=”modelname or componenetname”>
<service name=”services name or umo name”>
<inbound/>
<outbound/>
</service>
</model>
</mule>
Configuration file for mule resides in <Mule_HOME>/conf/ directory. Sample or default config file is available at
<MULE_HOME>/src/mule-config.xml. Mule configuration file is version specific. Configuration file from old version
may not work with new version of Mule. Refer the attached configuration files to know more.
8
1 2009
To run Mule, you have to enter the following at the command prompt:
Where your-config.xml is the Mule configuration file you want to use (see Configuration Files above 1.4). If you do
not specify the -config parameter then Mule looks for the default file mule-config.xml. If needed, you can specify
more than one configuration file in a comma-separated list. This approach is useful for splitting up your Mule
configuration to make it more manageable. All configuration files must be on the classpath prior to startup. A
convenient way to achieve this is by placing them in the /conf or /lib/user directory. Alternatively, you can specify an
explicit path to their location on the file system.
If you make changes to a configuration file, you must restart Mule for the changes to take effect.
To stop Mule, enter: Ctrl-C
Visit the following link to get more information about running mule.
http://mule.mulesource.org/display/MULE2INTRO/Running+Mule
9
1 2009
Note: To run this example user need few third party libraries. These libraries are downloaded at the time of building /
compiling via Ant. User needs appropriate target for proxy settings in their build.xml file. Proxy settings are missing in
provided build.xml file. Use this attached build.xml to build / compile the source code.
10
1 2009
All other examples can be run in the same way explained above. Visit the following link for more examples
http://mule.mulesource.org/display/MULE2INTRO/Home
11
1 2009
Download plugin
http://dist.muleforge.org/mule-ide/MuleIDE-2.0.0.M2-I200804251604.zip
1.7.2. Prerequisites
• Java 5 or higher
• Eclipse 3.3 in running & working state.
Mule IDE has been tested with the Europa (3.3) version of Eclipse IDE for Java Developers using a Java 5 JRE.
12
1 2009
7. Now restart the eclipse & follow the same steps to install plug-in MuleIDE-2.0.0.M2-I200804251604.
13
1 2009
4. Run application on mule server using configuration file shown in the figure below.
14
1 2009
15
1 2009
Visit the following link to know more about mule spring integration.
http://mule.mulesource.org/display/MULE2USER/Spring
16
1 2009
• Connector
A connector is the object that sends and receives messages on behalf of an endpoint. Connectors are bundled as
part of specific transports or providers.
• Transformer
Transformers are used to convert inbound data to an object type required by the UMO Component or outbound
to an object type required by the transport such as a JmsMessage. Transformers can be configured on Endpoints
that receive data to ensure that the expected object type is always received by an UMO Component.
Transformers configured on an Outbound endpoint ensure that the endpoint receives the the correct object type
before dispatching the event. Multiple transformers can be chained together to allow for finer grained
transformer implementations that are easier to reuse. To configure an Endpoint to use more than one
transformer, just specify a space separated list of transformers in the config file or programmatically chain the
transformers together using the setTransformer() method on the transformer.
• Interceptor
An interceptor is a piece of code that can be configured to execute before and/or after an event is received for a
component. User can define a stack of interceptors that will be executed in sequence. User can then configure
the stack on your components. Note the interceptor stack must not be a singleton. Each component needs its
own copy of an interceptor stack.
17
1 2009
Or follow the steps given in section 1.7.4 to run spring application using mule server via eclipse.
18
1 2009
This example is about Restaurant Service. This application consists of following package.
com.agilent.mulespring
This package consists of following classes & one application config file.
RestaurantWaiter.java
RestaurantWaiterInput.java Transformer
RestaurantWaiterPayload.java Payload
KitchenService.java
KitchenServiceInput.java Transformer
KitchenServiceOutput.java Transformer
KitchenServicePayload.java Payload
In this application it is show how to start mule service via spring application context xml file. You can see the config
file attached in section 1.8.1
19
1 2009
This example demonstrates that two spring components can exchange messages / objects using mule services. This
application is ready & working in my Eclipse environment. If the readers want to have a glance to code the let me
know I will share the project.
Note: Currently this example is implement using mule 1.4.3. Documentation & examples for Mule 2.0 is not available
for now. We need to do little investigation for the same.
20
1 2009
With ESB
21
1 2009
Mule is a light-weight messaging framework. It is a highly distributable object broker that can seamlessly handle
interactions with other applications using disparate technologies, transports and protocols. Mule was designed
around the Enterprise Service Bus architecture Mule's ultimate goal is to be the "Swiss-army knife" of integration.
Mule talks lots of different protocols
• HTTP, JMS, TCP, POP3, FTP, RMI, JDBC, Quartz.
• LDAP, JCR, Sales force.
Mule can route, transform and filter messages, transactions, security, management etc.
Mule support the following implementations of JMS.
• ActiveMQ
• JBoss MQ
• Joram
• OpenJms
• Oracle AQ
• SeeBeyond
• SonicMQ
• Sun JMS Grid
• Tibco EMS
• UberMQ
22
1 2009
• Weblogic Jms
• IBM WebSphere MQ
• SwiftMQ
• FioranoMQ
We have looked in to ActiveMQ implementation of JMS. Following is the JMS ActiveMQ configuration. This
configuration will go in mule-config.xml file.
I am not able to implement JMS using spring application. Investigation is going on for the same. I will update this
document with all my findings.
This application is a sample application to demonstrate mule event bus using ActiveMQ JMS.
23
1 2009
Sample application comprises of two components as show above Component1 & Component2. Both component take
inputs from console & send it to other component that display it on console. User has to type message from console.
Component1 is a publisher of topic my.q1 & Component2 is a consumer of topic my.q1 & viceversa. Both
components exchanges messages using ActiveMQ JMS.
Note: ActiveMQ server is running on machine1. Mule is not JMS server. We need to run ActiveMQ server separately.
Message exchange between these two components is using ActiveMQ JMS. We have to provide following
information in mule-config.xml
Connectors:
Transformers:
Interceptors:
Application Components:
24
1 2009
25
1 2009
Both components shown above consist of two UMOs i.e PublisherUMO & ConsumerUMO.
26
1 2009
As show in above configuration setting, publisherUMO is reads input from console & send it to other component.
ConsumerUMO receives JMS message from other component & displays that message on the console.
Execution
Following figure shows, sender sends a message using publisherUMO & receives an response using consumerUMO.
27