Upload
prudhvivreddy
View
429
Download
0
Embed Size (px)
Citation preview
PRUDHVI
Basic Example using Choice component
PRUDHVI
Abstract
Simple basic example to know how to use Choice component in mule studio/anypoint.
PRUDHVI
Introduction
The choice flow control dynamically routes messages based on message payload or properties. It adds conditional programming to a flow, similar to an if/then/else code block.
A choice flow control uses expressions to evaluate the content of a message, then it routes the message to one of the routing options within its scope
PRUDHVI
Basic Flow
PRUDHVI
<?xml version="1.0" encoding="UTF-8"?><mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:vm="http://www.mulesoft.org/schema/mule/vm" 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" version="EE-3.6.1" 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.xsdhttp://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsdhttp://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsdhttp://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsdhttp://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd"> <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/> <flow name="UsingChoiceRouter" > <http:listener config-ref="HTTP_Listener_Configuration" path="/choice" doc:name="HTTP"/> <set-payload value="#[message.inboundProperties.'http.query.params'.Mule]" doc:name="Set Payload"/> <choice doc:name="Choice"> <when expression="#[payload=='True']"> <logger message="True--#[payload]" level="INFO" doc:name="True"/> </when> <otherwise> <logger message="False--#[payload]" level="INFO" doc:name="False"/> </otherwise> </choice> </flow></mule>
FLOW:
PRUDHVI
URL: http://localhost:8081/choice/?Mule=True
Output:INFO 2015-10-10 01:24:45,192 [[poc].HTTP_Listener_Configuration.worker.01] org.mule.api.processor.LoggerMessageProcessor: True—True
PRUDHVI
Trigger : http://localhost:8081/choice/?Mule=TrueWe are setting the payload coming from http request.By using #[message.inboundProperties.'http.query.params'.Mule]The value for Mule is TrueIn Choice router:For True condition: #[payload=='True']For False Condition we are setting it default.
If we pass Mule=True, condition will satisfy and selected code will be executed.If false(Mule=any value), code will be executed in default.
Execution:
PRUDHVI
References
https://docs.mulesoft.com/mule-user-guide/v/3.5/choice-flow-control-reference#changing-the-default-route
PRUDHVI
Thank You