Mule Routers

Routers in Mule ESB play major roles to control the workflows. The router takes input, do the analysis and take the decision that will decide the next destination for the message. It is similar to the control statements in java language like if, if-else, switch etc. In Mule platform, they created many routers already to save the time of the developer while create the workflow. 

mule choice router

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

<mule xmlns:json="http://www.mulesoft.org/schema/mule/json" 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://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd">
    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
    <flow name="demo2Flow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/demo1" allowedMethods="POST" doc:name="HTTP"/>
        <object-to-string-transformer doc:name="Object to String"/>
        <choice doc:name="Choice">
            <when expression="#[payload=='1']">
                <set-payload value="ONE" doc:name="Set Payload 1"/>
            </when>
            <when expression="#[payload=='2']">
                <set-payload value="TWO" doc:name="Set Payload 2"/>
            </when>
            <when expression="#[payload=='3']">
                <set-payload value="THREE" doc:name="Set Payload 3"/>
            </when>
            <otherwise>
                <set-payload value="Not Available" doc:name="Set Payload"/>
            </otherwise>
        </choice>
        <set-payload value="Converted = #[payload]" doc:name="Set Payload"/>
    </flow>
</mule>

choice router example mule.

Tags