Home

Hello World Sample in Mule ESB

Introduction
This artical demonstrates a simple HTTP request-response activity. Mule responds to end user calls submitted via Web browser with a message that reads, "Hello <name>". This example was designed to demonstrate the ability of a Mule application to interact with an end user via an HTTP request. The goal is to introduce users to Anypoint Studio by illustrating a very simple functionality.
Implementation
As part of implementation we need to follow below steps.
Ø  Create a Mule Project.
Ø  Implement the Logic.
Ø  Test the application.
Create a Mule Project:
Open Anypoint Studio, Select File à New à Mule Project.
Enter Project Name as ‘HelloWorldSample’. Select the Runtime, I have selected as Mule Server 3.8.4 EE than click on Finish.
It will open empty HelloWorldSample Canvas as shown below.
Implement the Logic:
Search for http in the palette and drag the HTTP connector to the canvas. This action creates the flow named HelloWorldSampleFlow.
Search for set payload and drag the Set Payload transformer to the Process section of the flow.
Search for log in the palette and drag the Logger to the right of Set Payload.
Select the HTTP connector in the flow. In Basic Settings in the properties editor, change the Path to * (asterisk) to allow any path in the browser. For example, with the * setting in place, you can use a browser address like 0.0.0.0:8081/any path. You need this flexibility later when you extend the application.
In General Settings, click the green plus sign to the right of Connector Configuration. The Global Element Properties dialog appears:
Select localhost from dropdown of Host element and Port 8090.
Later, you use the host IP address and port number localhost:8090 in a browser to view the application response.
Click the Set Payload transformer to set its properties, and in the Value field, replace the \#[] value with Hello #[message.inboundProperties[‘http.query.params’].name]
Select the Logger component to set its properties, and in the Message field enter #[payload].
Test the application:
 Click the top project name in Package Explorer and click Run > Run As > Mule Application:
Click OK to save and launch the application.
The console lists output that looks something like this:
Open a browser and type the address http://localhost:8090/HelloWorld?name=Akshaj. You see the payload, Hello Akshaj:
Conclussion
We have build a simple service using Mule ESB. Here we just created a Mule Project and implemented with basic connector and transformation. We will have look into how to use Mule to build a simple HTTP request-response logging application in next articals.
Download
S. No
File Name
Size
Download
1
Hello World Sample in Mule ESB.pdf
400 KB

Comments