Nav

Tutorial: Creating a Mule App

Learn to create a "Hello World" Mule project, then deploy it as a Mule application through Anypoint Studio’s embedded Mule server. Finally, test your app by interacting with it using a web browser.

Prerequisites

  • You should have already downloaded, installed, and launched Anypoint Studio, which comes with an embedded Mule runtime instance.

  • You should understand the concepts of Mule Runtime and Mule application design.

Create a New Project

  1. In Anypoint Studio, choose File > New > Mule Project.

  2. Studio opens the New Mule Project wizard. In the Name field, enter the value Basic Tutorial, then click Finish.

    new

    Studio opens a new blank project. The following quick reference explains the different views you use to build a Mule project:

    blank+canvas

  3. To begin your project, drag an HTTP Connector from the palette to the canvas.

    add+http

    Studio automatically wraps the connector with a flow, thus saving you the step of manually creating one. There will be a red error dot overlaid on the HTTP connector because you have not configured it yet.

  4. Add a Set Payload component to the flow by dragging it to the right of the HTTP connector, as shown here.

    set+payload

    Anypoint Studio positions the Set Payload component next to the HTTP connector. The arrows signify the direction in which the Mule messages transition through the flow components.

    The Set Payload component sets the message payload to a value you define.

  5. Click Message Flow (Visual Editor) and then Configuration XML (XML Editor) tabs below the canvas to alternate between the editors so that you can see how Studio provides both a visual and code representation of your project.

  6. Click the Message Flow tab to return to the graphical editor.

  7. Click Save studio-save-button.

Configure the Flow Elements

Now that you’ve created a basic application in Studio, you are ready to configure your flow elements.

You need to provide the HTTP connector with a connector configuration that includes:

  • Name

  • Host

  • Port

The HTTP connector allows your Mule application to connect to Web resources through the HTTP or HTTPS protocol.

  1. In the canvas, click the HTTP connector to open its Properties Editor.

  2. Click the plus sign plus to add a Connector Configuration with a host and port number.

  3. In the Global Element Properties dialog, set Host to localhost, accept the default port 8081, click OK.

    http-global-config

    The properties window opens, with Path populated with " / " and Connector Configuration populated with a reference to the global element you just created.

  4. In the canvas, click the HTTP connector.

    The red warning marks disappear from the properties editor and the connector on the canvas.

  5. Click the Set Payload component on the canvas to open its properties editor in the console.

  6. Set the Value field to Hello World! for example.

    set+payload+hello+world

  7. Click the Configuration XML to view your changes in XML:

    
                
             
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    
    <?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_Configuration"
        host="localhost" port="8081" doc:name="HTTP Listener Configuration"/>
        <flow name="basic_tutorialFlow">
            <http:listener config-ref="HTTP_Listener_Configuration"
            path="/" doc:name="HTTP"/>
            <set-payload value="Hello World!" doc:name="Set Payload"/>
        </flow>
    </mule>
  8. Click the Save icon to save your changes.

You have now built a simple Mule application.

Deploy and Test Your Project Locally

Anypoint Studio has an embedded Mule runtime that you use to test deployments. You can deploy your application on the embedded server to see it working and perform any debugging activities before deploying to a production environment, such as an on-prem server or Runtime Manager.

  1. In the Package Explorer, right-click the project name, then select Run As > Mule Application.

    Studio launches the application on the embedded server, displaying its actions in the console. When complete, the console message reads:

    "Started app 'basic_tutorial'"

    console output

  2. Open your favorite Web browser. 

  3. Navigate to the URL of your application.

    This address is the result of the default settings of the HTTP connector:

    http://localhost:8081

    The application accepts the request via its HTTP endpoint, then the Set Payload component sets the payload to "Hello World!", and then HTTP connector returns the payload as the response you see in your browser.

    hello+world

  4. In Studio, stop the application from running by clicking Terminate stop.icon above the console.