Choice Router in Mule 4 | Choice in Mule 4

Choice Router in Mule 4
Content-based routing is used to examine messages and route them to the correct channel or destination depending on a message's content. We use content-based routing when we want to route messages to the right destination.

Choice Flow Control

In Mule, the choice flow control is used to achieve content-based routing where routing will be done based on the message content, like inbound properties, flow variables, and payload. A choice router will always choose only one route. If no route matches, then the default route is used. In a choice router, we use the MEL expression to specify the path for the message.

Below is Choice in mule 4:

In above example if input payload is equal to 1 then it moves to first branch otherwise print to default.

URL: http://localhost:8085/choice
Method: POST




XML project code:

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

<mule xmlns:http="" xmlns=""
       xmlns:xsi="" xsi:schemaLocation="">
       <http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="f5c2981b-49f5-4fe1-a84a-4daf08245ebe" >
              <http:listener-connection host="" port="8085" />
       <flow name="test_choiceFlow" doc:id="49a32c7c-5f0f-4e65-938d-4922614f7f09" >
              <http:listener doc:name="Listener" doc:id="78aa218d-be76-4611-b813-0335a8b24206" config-ref="HTTP_Listener_config" path="/choice"/>
              <choice doc:name="Choice" doc:id="1fc0ccf2-8e15-4cac-a1d1-fc094c608259" >
                     <when expression="#[]">
                           <set-payload value="#[payload]" doc:name="Set Payload" doc:id="37201df9-8a31-4a97-bef8-4b62a3ce9070" />
                     <otherwise >
                           <set-payload value="default" doc:name="Set Payload" doc:id="b4624434-427e-44fb-a167-e31d01a20d71" />

© 2020

Share on :

Mule 4:

XML to JSON in mule 4 Web service consumer VM Validation in Mule 4 Until Successful
Sub flow Set Variable & Remove Variable Set Transaction ID Scatter Gather Round Robin
Consume Restful Service CRUD in Mule 4 Parse Template Object to JSON Load Static Resource
JSON to XML Invoke Idempotent Filter ForEach Flat file to JSON
Fixwidth to JSON First Successful File Execute Error Handling
Email Dynamic Evaluate Custom Business Event CSV to JSON Copybook to JSON
Choice Router Async RabbitMQ

Mule 3:

Database Connector Async CXF Attachement XSLT
Mongo DB Cache scope Custom Business Event Gzip Compress Expression
SMTP For Each Expression Javascript Filter Reference
Salesforce Message Enricher Groovy Parse Template Idempotent
VM Poll Invoke Ruby Message
Webservice consumer Python Transformer reference Message Property Not
Collection Aggregator First Sucessful Catch Exception Strategy Reference Exception Strategy Or
Choice Message Chunk Aggregator Choice Exception Strategy Global Exception Strategy Schema Validation
Custom Aggregator Scatter Gather Custom Exception Strategy Batch Processing MEL
M Unit RAML Map Operator API Mocking Dataweave