Contact Free trial Login

Mule Components

MuleSoft recommends against deployments to Mule 3.8. Standard Support for this version ended on November 16, 2018, and Mule 3.8 will reach its End of Life on November 16, 2021, when Extended Support ends.

Components are message processors which execute business logic on messages. They enable you to perform specific actions without writing any Mule-specific code. You can drop a component – a POJO, Spring bean, Java bean, or script – into a flow to perform almost any customized task within your Mule application. For example, you can use a component to verify that items on an invoice are in stock in a warehouse, or to update a database with a customer’s order history.

Scripting Components

Mule includes several scripting components that you can use in flows to execute custom business logic. These components enable you to drop a chunk of custom-written logic into your flow to act upon messages.


The example below illustrates the use of a Groovy script component. The script uses the value of state to determine which of four sales regions to assign a lead.

Web Service Components

Also included are two components to facilitate exposing, consuming, and proxying Web services. The CXF component leverages the CXF framework Mule uses to support SOAP Web services; the REST component works with Jersey to support RESTful Web services; both are bound to HTTP.

rest cxf
APIkit offers a new and improved way of building a REST API. Access the APIkit Documentation to learn how to build REST APIs in a few hours or days.

HTTP Static Resource Handler

Further, Mule provides an HTTP static resource handler to facilitate working with calls over HTTP. Use the HTTP Static Resource Handler to easily serve up static content when called.


Other processors Grouped Under Components

Finally, Mule includes several other processors designed to meet rather specific needs.

  • Use a Logger component to log activities in the flow as they occur.

  • Use an Expression component to evaluate a particular expression upon a message in a flow.

  • Use an Invoke component to invoke the method of an object specified with a Mule expression.

  • Use an Echo component to return the payload of a message as a call response.

  • Use a Flow Reference component to access another flow from within a flow.

  • Use a Batch Execute component to kick off processing of a batch job.

Groovy Script Component Example

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:scripting=""

<!-- Other namespaces and schema locations as needed -->

    <flow name="LookUpSalesRegionFlow" doc:name="LookUpSalesRegionFlow" doc:description="The script uses data in the state field to add a region to the payload according to location.">
        <scripting:component doc:name="Groovy">
            <scripting:script engine="Groovy">def region = "UNKNOWN"
def state = payload['state']
if (state != null) {
 state = state.toUpperCase()
println "State to lookup is: " + state
switch (state) {
        case ["CT","ME","MA","NH","VT","RI","NY","NJ","DE","DC","MD","NH"]:
            region = "North East"
        case ["AL","AR","FL", "GA","LA" ,"SC","NC","TN","TX"]:
            region = "South East"
        case ["ID","IL", "IA","KS","MT", "WY","ND","SD","OH" ]:
            region = "Mid West"
        case ["AZ","CO","OK","NM", "NV"]:
            region = "South West"
        case ["CA","HI","WA","OR", "AK"]:
            region = "West Coast"
return ["region":region]</scripting:script>
        <logger message="Region is : #[payload.region]" level="INFO" doc:name="Logger"/>


REST Component Example

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:jersey="" xmlns:http="" xmlns="" xmlns:doc="" xmlns:spring="" xmlns:xsi="" xsi:schemaLocation=""/>
<http:listener-config name="HTTP_Listener_Configuration"
  host="localhost" port="8081" doc:name="HTTP Listener Configuration"/>
    <flow name="rest_exampleFlow1" doc:name="rest_exampleFlow1">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
        <jersey:resources doc:name="REST">
            <component class="example.RestExampleResource"/>

REST Example Resource


package example;


public class RestExampleResource {


    public String getExampleMsg(){
        return "REST and be well.";
        //return Response.status(Status.OK).entity("Rest and be well.").build();



Echo, Logger, and HTTP Resource Handler Examples

HTTP Listen and Choose


In the following example, you can try different values from this URL:

If you enter choice=mules, the flow succeeds and returns a status of 200 (okay); otherwise any other value returns a choice of null and a status code of 400 (bad request).

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http=""
    xmlns="" xmlns:doc=""
<http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8081" doc:name="HTTP Listener Configuration"/>

    <flow name="ListenAndChoose">
      <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
      <choice doc:name="Choice">
          <when expression="#[message.inboundProperties.'http.query.params'.choice == 'mules']">
              <set-variable variableName="status" value="200" doc:name="Variable"/>
              <set-variable variableName="status" value="400" doc:name="Variable"/>
       <set-payload value="Debug: Choice = #[message.inboundProperties.'http.query.params'.choice], Status value is #[flowVars.status]" doc:name="Debug Message"/>
       <echo-component doc:name="Echo"/>
       <logger message="#[payload]" level="INFO" doc:name="Logger"/>

HTTP Static Resource Handler

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="" xmlns="" xmlns:doc="" xmlns:spring="" xmlns:xsi="" xsi:schemaLocation="">
<http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8081" doc:name="HTTP Listener Configuration"/>
    <flow name="static-handlerFlow1" doc:name="statice-handlerFlow1">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
        <http:static-resource-handler resourceBase="src/main/resources/index.html" doc:name="HTTP Static Resource Handler"/>

See Also

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub