Mule 4 Mulesoft Basics Mulesoft Tutorial

Variables in Mule 4

Variable in Mule 4


In this Variable in Mule 4 tutorial we will look how we can create and use mule variable in Mule 4, and how it is different from Mule 3 and Mule 4.

In Mule 3 we had Flow variables, Session variables and record variable to store the data inside mule flow. But now in Mule 4 this has been changed; session variable and record variable has been removed and there is only Flow Variable.

As in Mule 3, Flow Variable in Mule 4 value is lost even when the flow crosses the transport barrier.
Session variable has been completely removed in Mule 4.

In Mule 4, flow variables have been enhanced to work efficiently during batch processing, just like the record variables. Flow variables created in batch steps are now automatically tied to the processing record and stays with it throughout the processing phase. No longer record variables are needed.

Setting Variable in Mule 4:


Setting mule flow variable is same as setting on Mule 3.

setvariable

<set-variable value="100" doc:name="Set Variable" doc:id="38b1b708-551c-404b-970e-37078ee04b41" variableName="var1"/>
Accessing Mule Variable Value:


In Mule 4 you can now access variable value by “vars” keyword instead of “flowVars” in Mule 3 – #[vars.var1]

logvariable

 <logger level="INFO" doc:name="Logger" doc:id="f8736e1b-39b9-4cce-b612-757d995cc7e7" message="var1 = #[vars.var1]"/>

 

Accessing Mule Variable from DW:


Variable can be accessed inside Dataweave 2.0 by “vars” keyword – vars.var1

  <ee:transform doc:name="Transform Message" doc:id="57cfb4b0-5b46-4e7f-bfa8-8cda6550822d" >
   <ee:message >
    <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
{
 a: vars.var1
}]]></ee:set-payload>
   </ee:message>
  </ee:transform>

 

Varun Goel

About Varun Goel

Varun Goel is a technology enthusiast with 6+ years exp in IT industry. In fact, he is been developing application after schooling as freelancer. Currently working with one of the Fortune’s 100 Companies having vast experience Mule ESB, Tibco, HTML5, CSS, JSS, Android, Core Java, JSP, PHP, MySQL, AutoCAD, Maya, ZBrush, Photoshop, Flash CS and many more.

Leave a Reply

Your email address will not be published.