Table of Contents
What is Mule ESB?
Mule, the runtime platform and a nimble Java-based enterprise service (ESB) which allows developers to easily build high-performance, secure, multi-protocol interactions between heterogeneous systems and services. It enables easy integration of existing systems, regardless of the different technologies that the applications use. The exchange of data between applications is carried by different messaging format.
Following are the powerful capabilities of Mule ESB:
- Data Transformation
- Service Mediation
- Service creation and hosting
- Message Routing
Advantages of Mule ESB
- Lightweight but scalable, permitting you to start small and connect more applications in future.
- Well suited to the scenarios where loose coupling, robustness, and scalability required.
- It has support for more than 30 protocols and technologies.
- Mule platform encourages component reuse profusely; no need to run or add Mule specific code in any of the component. Also, the business logic is separated from messaging logic.
- Mule does not force any design constraints while choosing messaging format. It varies from SOAP to Binary image files.
Mule ESB Architecture
Mule Message Structure
It is the data format which is internally used by Mule to communicate between different applications via one or more flows.
Primarily it consists of two main parts:
- Header — which is nothing but the metadata of message.
- Payload — which is the actual business message.
Message Object is used to envelop the Mule Message along with some extra attributes like Attachment, Variable, and Exception Payload — which may not appear in every case.
The metadata is represented by properties— which provides useful information in order to facilitate processing and avoid errors when the message enters new flow or being transmitted to another application. Properties and Variables, contained within Mule Object, keep data in key-value format.
Properties have two main scopes:
- Inbound Properties:
- These are immutable, automatically generated by the message source.
- They deter scrambling of data formats and any other manipulation in message lifecycle.
- Inbound properties’ scope is limited to only a flow; once message whisks to another flow, its inbound properties are disappeared.
- Mule Expression Language (MEL) Example:
- Outbound Properties:
- These are mutable and can be set by Mule or a user can alter them by using transformer elements in the flow.
- They can become inbound properties when message passed outbound endpoint of one flow to inbound endpoint of another flow.
- In one case—if message is passed to any flow-ref, then the outbound properties remain same as outbound properties.
- MEL Example:
Variables have three scopes:
- Flow Variables— can be accessed within the same flow.
- Session Variables— apply across the flows within the same application.
- Record Variables— apply to only to records processed under batch
Message Payload contains the data your Mule application processes. Payload changes during its journey through different flow. It is set, enriched, or transformed into the new format by various of a Message processor in a Mule flow.
MEL Example to extract payload information:
Mule Runtime Setup
- Mule Runtime Community (CE) or Enterprise (EE) edition is available here:
- For installing Anypoint Studio, the IDE for creating integration applications, click here:
Anypoint Studio Hello World Project
Let’s construct an application step by step which returns “Hello Mule” message to the browser when you hit the service.
- Launch the Anypoint Studio platform by navigating to a directory on your local machine where you installed.
- Create new Mule project, either by hitting “Create Project” link appeared on the Welcome screen or by navigating to File > New > Mule Project.
- Enter the name of your project in “Project Name” section.
- Click on Finish, and you will see Studio Canvas screen as following:
- At the bottom of canvas there are three tabs—Message Flow, Configuration XML and Global Elements. Message Flow and Configuration XML are the two tabs to show or edit Mule flow in visual and xml format, respectively. Global Elements tab exudes properties for configuration elements having scope global.
- Select a HTTP connector from Mule Palette and drag it into canvas.
- Go to the HTTP Listener configuration panel – clicking on green plus symbol under General settings in HTTP Connector – and enter Host and Port values.
- Search for the Set Payload and drag the transformer to the flow.
- Click on Set Payload transformer and set the Value field as “Hello Mule”.
- Drag the Logger and set the payload value received from Set Payload transformer into Message.
- After connecting all the Mule components, you flow, in XML format, looks like this:
<flow name="hellomuleexampleFlow"> <http:listener config-ref="HTTP_Listener_Configuration" path="/message" doc:name="HTTP"/> <set-payload value="Hello Mule" doc:name="Set Payload"/> <logger message="#[payload]" level="INFO" doc:name="Logger"/> </flow>
- To test your application — run it as Mule Application. You can see console logs as below to verify the application is deployed and started successfully.
- Fire up the browser and hit the address
http://localhost:8081/message. You can see response as “Hello Mule”.