Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Creating a Mule ESB Sample Application

DZone's Guide to

Creating a Mule ESB Sample Application

Mule is a lightweight, open source integration framework. In this tutorial, learn the requirements and steps for creating a sample Mule application.

· Integration Zone
Free Resource

Share, secure, distribute, control, and monetize your APIs with the platform built with performance, time-to-value, and growth in mind. Free 90 day trial 3Scale by Red Hat

Mule ESB is an integration technology which can connect different applications. Mule is an open source integration framework consisting of different Connectors which can easily integrate our applications.

Mule is a lightweight integration framework. Mule ESB includes powerful capabilities including REST, SOAP, JMS, Salesforce, Cloudhub, RAML, Http, Datasource, Dataweave, Java, and MongoDB.

MuleSoft Anypoint Studio is a user-friendly IDE where we can easily drag Connectors from the Mule Palette.

In this article, I am going to show you how to create a Mule ESB Sample Application. For this, we need the below requirements.

1. Java 8 (JDK 1.8)

2. Anypoint Studio

3. Postman

Mule ESB Sample Application

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">

  <http:listener-config name="HTTP_Listener_Configuration1" host="0.0.0.0" port="8081" basePath="/sample" doc:name="HTTP Listener Configuration"/>
    <flow name="sample-appFlow">
        <http:listener config-ref="HTTP_Listener_Configuration1" path="/{parmname}" allowedMethods="GET" doc:name="HTTP"/>
        <set-payload value="#[message.inboundProperties.'http.uri.params'.parmname]" doc:name="Set Payload"/>
    </flow>
</mule>

Follow the below steps or copy the above code into Mule Configuration XML (src/main/app/sample-app.xml).

Step 1: Open Anypoint Studio and Create a new project using File->New ->Mule Project.

To create New Project

Step 2: Type a Project Name like "sample-app" and press the Finish button.

Project Name

Step 3: Drag an HTTP Connector from Mule Palette.

Drag Http Connector from mule palette

Step 4: Click on the HTTP Connector and you can find HTTP Attributes in the below screen. We need to configure some details of the HTTP Connector.

Set Http Configure details

Step 5: Configure port "8081" and the Base path as "/sample" & press the OK button.

Http Configure Details

Step 6: Set the path as "/{paramname}" and Allowed Methods to "GET."

Http Configure Details

Step 7: Drag a Set Payload Connector from Mule Palette.

SetPayload Connector

Step 8: Click on Set Payload Connector and set the value.  #[message.inboundProperties.'http.uri.params'.parmname] 

SetPayload

Step 9: To run this application, right click on Mule Flow and select "Run Project sample-app."

How to run project

Step 10: You can see some logs in the console screen; the status is showing that the application was deployed.

Status Deployed

Step 11: Go to Postman:

                Select Method: "GET"

                URL: http://localhost:8081/sample/

                Param value: Helloworld

                Example: http://localhost:8081/sample/Helloworld

PostmanStep 12: To stop the application, go to Mule Flow, right click and select "Stop Project sample-app."

How to stop application

Discover how you can achielve enterpriese agility with microservices and API management

Topics:
mule esb ,mule ,mule flow ,integration ,tutorial

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}