DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Error Handling Wikipedia in MuleSoft
  • MDC Logging With MuleSoft Runtime 4.4
  • MuleSoft Integration With RabbitMQ
  • Object Store Connector in Mulesoft

Trending

  • When One MVP Is Really Four Systems: A Better Way to Plan Multi-Role Apps
  • Build a GitHub Slack Bot With AWS Bedrock and MCP, Part 1
  • Chaos Engineering Has a Blind Spot. Agentic AI Lives in It.
  • Why DDoS Protection Is an Architectural Decision for Developers
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. What Are Anypoint Flow, Session, and Property Variables in MuleSoft?

What Are Anypoint Flow, Session, and Property Variables in MuleSoft?

Variables can set or remove a variable tied to message in current flow, across multiple flows, or on the outbound scope of a message.

By 
Jitendra Bafna user avatar
Jitendra Bafna
·
Feb. 22, 17 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
34.0K Views

Join the DZone community and get the full member experience.

Join For Free

A MuleMessage is the object used to pass any data through Mule flow. MuleMessage consists of three parts:

  • Header, which contains set of named properties.

  • Payload, which actually contains message or data.

  • Attachment.

A Variable is used to set or remove a variable on message. The Scope Variable is limited to the flow where it is set. When a message leaves the flow, the variable doesn’t carry to next flow or application.

Flow Variable

The Flow Variable is used to set or remove the variable tied to message in current flow. Variables set by flow variable transformer persist for the current flow and cannot cross the transport barrier.

The Flow Variable can be accessed in current flow, calling flows (sub flow/private flow) and even their child flows.

The Flow Variable can be accessed using syntax #[flowVars.Id] if the Id is the name of flow variable.

Image title

<?xml version="1.0" encoding="UTF-8"?>
<mule
xmlns:file="http://www.mulesoft.org/schema/mule/file"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
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"
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/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd">
<flow name="flowexampleFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/GET" doc:name="HTTP"/>
<set-variable variableName="Id" value="#[message.inboundProperties.'http.query.params'.code]" doc:name="Variable"/>
<logger level="INFO" doc:name="Logger" message="#[flowVars.Id]"/>
</flow>
</mule>

Session Variable

The Session Variable is used to set or remove the variable tied to current message for its entire lifecycle across multiple flows and even servers.

Variables set by the Session Variable transformer persist for the entire lifecycle regardless of transport barrier. The Session Variable can be accessed in current flow, calling/child, flow within the entire project, and even JVM systems.

Session Variable can be accessed using syntax #[sessionVars.Id] if the Id is the name of the Session Variable.

Image title

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

<mule xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:http="http://www.mulesoft.org/schema/mule/http" 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" 
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/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd">
    <flow name="flowexampleFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/GET" doc:name="HTTP"/>
        <set-session-variable variableName="Id" value="#[message.inboundProperties.'http.query.params'.code]" doc:name="Session Variable"/>
        <logger level="INFO" doc:name="Logger" message="#[sessionVars.Id]"/>
    </flow>
</mule>

Property

The Property is used to set, remove, or copy the properties on the outbound scope of a message. Once a message hits an outbound connector, all properties in the outbound scope are sent with the message in the form of transport-specific metadata (HTTP headers for an HTTP outbound-connector, for example).

Image title

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

<mule xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:http="http://www.mulesoft.org/schema/mule/http" 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" 
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/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd">
    <flow name="flowexampleFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/GET" doc:name="HTTP"/>
        <set-variable variableName="Id" value="#[message.inboundProperties.'http.query.params'.Id]" doc:name="Variable"/>
        <logger level="INFO" doc:name="Logger" message="#[flowVars.Id]"/>
        <catch-exception-strategy doc:name="Catch Exception Strategy">
            <set-property propertyName="http.status" value="400" doc:name="Property"/>
            <set-payload value="Bad Request" doc:name="Set Payload"/>
        </catch-exception-strategy>
    </flow>
</mule>

I hope that this article clarifies any confusion that you may have had with Flow, Session, and Property Variables.

Flow (web browser) Session (web analytics) Property (programming) MuleSoft

Opinions expressed by DZone contributors are their own.

Related

  • Error Handling Wikipedia in MuleSoft
  • MDC Logging With MuleSoft Runtime 4.4
  • MuleSoft Integration With RabbitMQ
  • Object Store Connector in Mulesoft

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook