0% found this document useful (0 votes)
16 views

Tutorial - Create A - Hello World - Mule App

MuleSoft Hello word

Uploaded by

jaime benavides
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Tutorial - Create A - Hello World - Mule App

MuleSoft Hello word

Uploaded by

jaime benavides
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

7/11/24, 12:01 PM Tutorial: Create a "Hello World" Mule app

Tutorial: Create a "Hello World"


Mule app
MuleSoft Documentation Site
5 min. read · View original

To demonstrate how a Mule application interacts


with a user in a simple HTTP request-response
flow, this example responds with the message
"Hello Mule" to requests submitted from a web
browser.

Note that this is a very simple example. In a more


complex application, you can connect to external
servers (such as SAP, Salesforce, a database, or
an FTP server), import and implement API
specifications directly within a Mule project, set
up security, and process and transform the data in
programmatic ways. It is beyond the scope of this
example to explore such tasks.

https://docs.mulesoft.com/mule-runtime/latest/mule-app-dev-hellomule 1/12
7/11/24, 12:01 PM Tutorial: Create a "Hello World" Mule app

Figure 1. hellomule in Anypoint Studio

You set up and run this application as a project in


Anypoint Studio.

Prerequisites
After Anypoint Studio is installed, you can set up
and run the example.

How the Example Works


The Hello Mule example consists of one simple
Mule flow. This flow accepts an HTTP request, sets
a static payload on the message, and then returns
a response to you.

The inbound HTTP endpoint receives requests


that are submitted to the web service. The HTTP
endpoint is responsible for receiving and returning

https://docs.mulesoft.com/mule-runtime/latest/mule-app-dev-hellomule 2/12
7/11/24, 12:01 PM Tutorial: Create a "Hello World" Mule app

messages because the message-exchange


pattern is request-response.

As its name suggests, the Set Payload component


sets a value in the message payload. In this
example, the value uses a DataWeave expression
to set a static string on the payload.

Set Up the Example


Follow these steps to create the example in your
own instance of Anypoint Studio. Note that you
can create template applications in Anypoint
Studio and tweak the configurations of the use
case-based templates to create your own
customized applications in Mule.

1. Create a project in Anypoint Studio named


hellomule:

a. Select File > New > Mule Project, and


provide the Project Name "hellomule" in
the dialog that opens:

Notice that the project name does not


contain any blank spaces.

b. Click Finish.

https://docs.mulesoft.com/mule-runtime/latest/mule-app-dev-hellomule 3/12
7/11/24, 12:01 PM Tutorial: Create a "Hello World" Mule app

2. Drag the HTTP Listener component to the


hellomule canvas:

a. In the project’s Mule Palette tab, click


HTTP:

b. Drag the Listener component into the


hellomuleFlow canvas:

If the configuration UI in the Listener tab


is not open, click the Listener component
in the canvas to open it.

Note that the red boxes in the tab are


present because the Connector

https://docs.mulesoft.com/mule-runtime/latest/mule-app-dev-hellomule 4/12
7/11/24, 12:01 PM Tutorial: Create a "Hello World" Mule app

configuration and Path fields require


values.

3. Configure the Listener component from the


Listener tab:

a. In the listener’s Path field, type the path


/hellomule.

b. Find and click the green plus icon (+)


beside the listener’s Connector
configuration field to open the HTTP
Listener config dialog.

c. In the dialog, check the default listener


configuration by clicking Test
Connection:

https://docs.mulesoft.com/mule-runtime/latest/mule-app-dev-hellomule 5/12
7/11/24, 12:01 PM Tutorial: Create a "Hello World" Mule app

If the connection is successful, you


see the message "Test connection
successful!" in a Test connection
dialog that pops up.

If the connection fails, try using a


port number that is not in use, such
as 8082 or 8083, retest the
connection, and then add the
configuration.

d. Click OK to add a working configuration


to the project.

4. From the Mule Palette tab, click Core, and


then find and drag a Set Payload component
to the Process area of the canvas:

https://docs.mulesoft.com/mule-runtime/latest/mule-app-dev-hellomule 6/12
7/11/24, 12:01 PM Tutorial: Create a "Hello World" Mule app

If you do not find the Set Payload


component, try the search field at the top
of the Mule Palette tab.

If the configuration UI in the Set Payload


tab is not open, click the Set Payload
component to open its configuration UI.

5. In the Set Payload component’s Value field,


deselect the fx field, and type the string
"Hello Mule!".

When you deselect fx, the field contains only


the string "Hello Mule" and does not
contain a hash (#) or square brackets ([]).

6. From the Mule Palette tab, click Core, and


then find and drag a Logger component to
the right of the Transform Message
component.

https://docs.mulesoft.com/mule-runtime/latest/mule-app-dev-hellomule 7/12
7/11/24, 12:01 PM Tutorial: Create a "Hello World" Mule app

7. In the logger’s Message field, click the fx


button, and add the following DataWeave
expression for printing the request path to
the Anypoint Studio console:

attributes.requestPath

8. Save the project by selecting File > Save from


Anypoint Studio.

9. Proceed to Run and Execute the Hello Mule


Example.

Run and Execute the Hello Mule Example


After setting up Hello Mule in Anypoint Studio, you
can run and test it.

1. Run your hellomule application by right-


clicking within the Anypoint Studio canvas
and selecting Run project hellomule.

https://docs.mulesoft.com/mule-runtime/latest/mule-app-dev-hellomule 8/12
7/11/24, 12:01 PM Tutorial: Create a "Hello World" Mule app

Alternatively, you can click the Run button (

) located at the top of Anypoint Studio, and


select hellomule from the drop-down menu
that opens.

Either action initiates the build process and


opens the Anypoint Studio console, where the
logs print important information about the
two-stage build and deployment process.

You know the project is running if you see a


message that ends something like this in the
Anypoint Studio console:

************************************************
**********
* - - + DOMAIN + - - * - - + STATUS +
- - *
************************************************
**********
* default * DEPLOYED
*
************************************************
**********

https://docs.mulesoft.com/mule-runtime/latest/mule-app-dev-hellomule 9/12
7/11/24, 12:01 PM Tutorial: Create a "Hello World" Mule app

************************************************
*******************************
* - - + APPLICATION + - - * - - + DOMAIN
+ - - * - - + STATUS + - - *
************************************************
*******************************
* hellomule * default
* DEPLOYED *
************************************************
*******************************

txt

If you receive a failure notification (FAILED)


in the console instead of the DEPLOYED
notification, check the error message. If you
see a message like the following one, try
setting a new HTTP port in your HTTP listener
configuration:

Could not create server: A server in port(8081)


already exists
for host(0.0.0.0) or one overlapping it
(0.0.0.0).`

txt

Then save and rerun your project. Note that


you can also try changing the host to
localhost if the failure persists.

2. After your application is running, open a


browser window, and enter the URL to the
listener to trigger the application:

https://docs.mulesoft.com/mule-runtime/latest/mule-app-dev-hellomule 10/12
7/11/24, 12:01 PM Tutorial: Create a "Hello World" Mule app

You must use the same host and port as


configured in the HTTP listener, for example,
http://0.0.0.0:8081/hellomule.

3. Check for the message Hello Mule! in the


browser.

4. In Anypoint Studio, notice that the message


in the Console tab includes the request path
(/hellomule) at the end of the first INFO
line
(org.mule.runtime.core.internal.pr
ocessor.LoggerMessageProcessor:
/hellomule).

Configuration XML for the Hello Mule


Example
The following XML provides the flow and HTTP
listener configuration for the example. To reserve
space, the example omits the doc:id attributes,
which are not required.

Configuration XML from Anypoint Studio:

https://docs.mulesoft.com/mule-runtime/latest/mule-app-dev-hellomule 11/12
7/11/24, 12:01 PM Tutorial: Create a "Hello World" Mule app

<http:listener-config name="HTTP_Listener_config"
doc:name="HTTP Listener config"
>
<http:listener-connection host="0.0.0.0"
port="8081" />
</http:listener-config>
<flow name="hello-muleFlow" >
<http:listener doc:name="Listener"
config-ref="HTTP_Listener_config"
path="/hellomule"/>
<set-payload value="Hello Mule!"
doc:name="Set Payload"
mimeType="text/plain"/>
<logger level="INFO"
doc:name="Logger"
message="#[attributes.requestPath]"/>
</flow>

XML

The XML Configuration tab below the canvas


provides an edit page for the XML:

https://docs.mulesoft.com/mule-runtime/latest/mule-app-dev-hellomule 12/12

You might also like