Adding a Component to Your Project
The following example illustrates basic configurations for adding components to your project from the canvas, and the configuration XML. The example assumes you are beginning with an empty integration project.
-
{open-config-xml}, such as
my-project-name.xml
.1 The canvas provides space for a visual representation of your Mule flows or subflows. 2 The configuration XML editor displays the configuration file for your Mule application. -
Select Build a Flow from the canvas to create an empty flow within a Mule integration application.
-
Change the default name of the flow from the canvas or from the configuration XML.
-
From the canvas
-
From the configuration XML
Click Flow name1 to open the configuration panel for the Flow component, change the flow name, and click the check mark to set the new name.
Replace the default name of the flow (
name1
) with your flow name, such asgetFlights
, for example:<flow name="my-flow" > </flow>
-
-
Add a component to your project from the canvas.
For example, add the HTTP Listener component:
-
In the canvas, click the (Add component) icon.
-
In the Add Component panel, search for and select Listener from the HTTP results:
The configuration XML file now includes the XML for the HTTP Listener within the
<flow/>
element, for example:<flow name="getFlights" > <http:listener path="mypath" config-ref="config-ref" doc:name="Listener" doc:id="rrjiqa" /> </flow>
-
-
Add another component, this time using the XML configuration menu.
For example, add the
<http:listener-config/>
component from a snippet.For more information about snippets, see Working with Code Snippets.
-
In the configuration XML, place your cursor before the opening
<flow>
tag, and typehttp
.Ensure that the cursor is not inside the
<flow/>
element. -
Type
http
, and select thehttp:listener-config
snippet:The snippet adds the following code:
<http:listener-config name="HTTP_Listener_config" > <http:listener-connection host="0.0.0.0" port="8081" /> </http:listener-config>
-
Notice that the Listener component in the canvas now displays an error:
-
To determine where the error is, select the processor in the canvas.
Anypoint Code Builder highlights its location within the configuration XML, and you can mouse over the issue for more information, for example:
-
To fix the error, change the value of the
name
attribute inhttp:listener-config
to match the name of theconfig-ref
value in yourhttp:listener
configuration:<http:listener-config name="config-ref" > <http:listener-connection host="0.0.0.0" port="8081" /> </http:listener-config>
The HTTP listener within your flow now references the HTTP listener configuration, a global connection configuration that resides outside of the flow. For more information about debugging, see Debugging Mule Applications.
-
-
Add another component to your flow.
For example, add a Set Payload component to your HTTP Listener operation:
-
In the canvas, click the (Add component) icon.
-
In the Add Component panel, search for and select Set payload from the Transformer results.
-
In the canvas, click Set payload to open its configuration panel, and add a string value, DataWeave expression, Mule variable, or configuration property.
-
To add a string, type a value such as
my value
. For example: -
To add a DataWeave expression or a Mule variable as a value, such as
payload
, click fx (located before the field), and provide the value, for example:For more information about configuring DataWeave expressions, see Configuring DataWeave Expressions.
-
To add a configuration property as a value, type a value such as
${secure::mysensitiveprop}
. For example:For more information about configuration properties, see Defining and Securing Properties for a Mule Application.
-
-
Your configuration XML file now looks similar to the following:
<http:listener-config name="config-ref" >
<http:listener-connection host="0.0.0.0" port="8081" />
</http:listener-config>
<flow name="getFlights" >
<http:listener path="path" config-ref="config-ref" doc:name="Listener" doc:id="rrjiqa" />
<set-payload value="my value" doc:name="Set payload" doc:id="gecykt" />
</flow>