Upload
abdulimrankhan7
View
333
Download
0
Embed Size (px)
Citation preview
Choice Component In Mule Demo
Abstract
• The main motto of this PPT is how to use Choice component in our applications.
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/elsecode block.
Example
• .mflow• <?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.4.0" 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/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.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/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">• <flow name="MessagePropertiesFlow1" doc:name="MessagePropertiesFlow1">• <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8089" path="choice" doc:name="HTTP"/>• <message-properties-transformer scope="session" doc:name="Message Properties">• <add-message-property key="property1" value="mule"/>• </message-properties-transformer>• <logger message="--flow1--#[sessionVars['property1']]" level="INFO" doc:name="Logger"/>• <vm:outbound-endpoint exchange-pattern="request-response" path="messageproperties" doc:name="VM"/>• </flow>• <flow name="MessagePropertiesFlow2" doc:name="MessagePropertiesFlow2">• <vm:inbound-endpoint exchange-pattern="request-response" path="messageproperties" doc:name="VM"/>• <logger message="---flow2--#[sessionVars['property1']]" level="INFO" doc:name="Logger"/>• <choice doc:name="Choice">• <when expression="#[sessionVars['property1']=='mule']">• <logger message="--the value of session property (property1) is 'mule'" level="INFO" doc:name="Logger"/>• </when>• <otherwise>• <logger message="--the value of session property (property1) is not 'mule'" level="INFO" doc:name="Logger"/>• </otherwise>• </choice>• </flow>• </mule>
• Output:
• INFO 2015-10-03 16:00:23,705 [[messageproperties].config.change.14.thread.1] org.mule.DefaultMuleContext: • **********************************************************************• * Application: messageproperties *• * OS encoding: Cp1252, Mule encoding: UTF-8 *• * *• * Agents Running: *• * Clustering Agent *• * JMX Agent *• **********************************************************************• INFO 2015-10-03 16:00:23,706 [[messageproperties].config.change.14.thread.1]
org.mule.module.launcher.MuleDeploymentService: • ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++• + Started app 'messageproperties' +• ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++• INFO 2015-10-03 16:00:26,480 [[messageproperties].connector.http.mule.default.receiver.02]
org.mule.api.processor.LoggerMessageProcessor: --flow1--mule--studio• INFO 2015-10-03 16:00:26,482 [[messageproperties].connector.http.mule.default.receiver.02]
org.mule.lifecycle.AbstractLifecycleManager: Initialising: 'connector.VM.mule.default.dispatcher.771015974'. Object is: VMMessageDispatcher
• INFO 2015-10-03 16:00:26,482 [[messageproperties].connector.http.mule.default.receiver.02] org.mule.lifecycle.AbstractLifecycleManager: Starting: 'connector.VM.mule.default.dispatcher.771015974'. Object is: VMMessageDispatcher
• INFO 2015-10-03 16:00:26,489 [[messageproperties].connector.http.mule.default.receiver.02] org.mule.api.processor.LoggerMessageProcessor: ---flow2--mule--studio
• Flow of execution:1. URL to trigger the service from browser http://
localhost:8089/choice 2. session property is created using message property component In flow1 3. Service displays session properties in flow1, flow24. In flow2 the choice component checks the value of the session property is ‘mule’ or not, if true then it displays “the value of session property (property1) is 'mule” else it goes and displays data in default component
References
• https://docs.mulesoft.com/mule-user-guide/v/3.5/choice-flow-control-reference