Thursday 15 December 2016

Textual Representation of logo

Mule Session And Flow Var Example

This is simple example in mule demonstrating use of SessionVar , FlowVar , SubFlow , Vm , ForEach ,Groovy and Expression Component .
<http:listener-config port="8081" host=""
  name="myRequestConfig" doc:name="HTTP Listener Configuration">
   maxThreadsActive="15" />

<flow name="foreachexample">
<http:listener path="/foreach/test" config-ref="myRequestConfig"
   allowedMethods="GET" doc:name="HTTP"/>
     <logger message="RUNNNING poller ra " level="ERROR"/>
            java.util.ArrayList list = new java.util.ArrayList();
            payload = list;
        <set-session-variable value="true" variableName="changeMe" doc:name="Session Variable" />
        <set-variable value="true" variableName="myFlowVar" doc:name="Flow Variable" />
        <foreach >
         <logger message="fdsf" level="ERROR"/>
         <flow-ref name="subFlowTest" />
         <flow-ref name="flow2" />
         <vm:outbound-endpoint path="/opt"/>
        <vm:outbound-endpoint path="/opt"/>
        <logger message="changeme : #[sessionVars.changeMe]" level="ERROR"/>
 <sub-flow name="subFlowTest">
  <logger message="changeme flow var in sub flow : #[flowVars.myFlowVar]" level="ERROR"/>
  <logger message="changeme session var in sub flow: #[sessionVars.changeMe]" level="ERROR"/>
  <scripting:component doc:name="sleep">
   <scripting:script engine="groovy">

 <flow name="flow2">
  <vm:inbound-endpoint path="/opt"></vm:inbound-endpoint>
  <logger message="changeme session var in flow 2: #[sessionVars.changeMe]" level="ERROR"/>
  <logger message="changeme flow var in flow 2: #[flowVars.myFlowVar]" level="ERROR"/>

FlowVars do not get lost when you call another flow by using flow-ref , but if you call another flow by vm or any other transport , then the flow variable will be lost and you will not be able to find it in the other flow .

SessionVars will be present in each and every flow till the execution of the call .
This example also demonstrates how can we write java code in our mule file using groovy component and expression component . Make sure to import the packages of the class which you intend to use , otherwise use fully qualified class name in your code .