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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

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

Trending

  • Traditional Testing and RAGAS: A Hybrid Strategy for Evaluating AI Chatbots
  • Advancing Robot Vision and Control
  • The Perfection Trap: Rethinking Parkinson's Law for Modern Engineering Teams
  • The Role of AI in Identity and Access Management for Organizations
  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
DZone Core CORE ·
Feb. 22, 17 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
33.7K 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
Oops! Something Went Wrong

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

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!