Mule ESB - Getting Started With Examples

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 ESB Architecture

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.

mule-message-structure

 

Mule Message Structure

Primarily it consists of two main parts:

  1. Header — which is nothing but the metadata of message.
  2. 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:
    1. These are immutable, automatically generated by the message source.
    2. They deter scrambling of data formats and any other manipulation in message lifecycle.
    3. Inbound properties’ scope is limited to only a flow; once message whisks to another flow, its inbound properties are disappeared.
    4. Mule Expression Language (MEL) Example: #[message.outboundProperties]
  • Outbound Properties:
    1. These are mutable and can be set by Mule or a user can alter them by using transformer elements in the flow.
    2. They can become inbound properties when message passed outbound endpoint of one flow to inbound endpoint of another flow.
    3. In one case—if message is passed to any flow-ref, then the outbound properties remain same as outbound properties.
    4. MEL Example: #[message.inboundProperties]

Variables have three scopes:

  1. Flow Variables— can be accessed within the same flow.
  2. Session Variables— apply across the flows within the same application.
  3. 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: #[payload]

Mule Runtime Setup

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.

    1. Launch the Anypoint Studio platform by navigating to a directory on your local machine where you installed.
    2. Create new Mule project, either by hitting “Create Project” link appeared on the Welcome screen or by navigating to File > New > Mule Project.
    3. Enter the name of your project in “Project Name” section.

Anypoint Studio Create New Project

Anypoint Studio Create New Project

    1. Click on Finish, and you will see Studio Canvas screen as following:

Anypoint Studio Hello World Project Structure

Anypoint Studio Hello World Project Structure

    1. 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.
    2. Select a HTTP connector from Mule Palette and drag it into canvas.

Anypoint Studio Hello Mule HTTP Connector

Anypoint Studio Hello Mule HTTP Connector

    1. Go to the HTTP Listener configuration panel – clicking on green plus symbol under General settings in HTTP Connector – and enter Host and Port values.

mule-http-connector-settings

Mule ESB HTTP Connector Settings

Mule ESB HTTP Listener Configurations

Mule ESB HTTP Listener Configurations

    1. Search for the Set Payload and drag the transformer to the flow.

Mule Message Set Payload

Mule Message Set Payload

    1. Click on Set Payload transformer and set the Value field as “Hello Mule”.
    2. mule-message-payload-value

Mule Message Payload Value

    1. Drag the Logger and set the payload value received from Set Payload transformer into Message.

Anypoint Studio Logger

Anypoint Studio Logger

    1. After connecting all the Mule components, you flow, in XML format, looks like this:
    2. 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.

Anypoint Studio Run As Mule Application

Anypoint Studio Run As Mule Application

    1. Fire up the browser and hit the address https://localhost:8081/message. You can see response as “Hello Mule”.
    2. mule-hello-world-web-application

Mule Hello World Web Application

By admin

Leave a Reply

%d bloggers like this: