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 Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
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
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. The Scope of Flow Variables and Session Variables in Async Flow in Mulesoft

The Scope of Flow Variables and Session Variables in Async Flow in Mulesoft

In this article, we will see how these variables are processed in an async scope of a flow.

Radhika A user avatar by
Radhika A
CORE ·
Jan. 16, 19 · Tutorial
Like (4)
Save
Tweet
Share
20.00K Views

Join the DZone community and get the full member experience.

Join For Free

Mule variables are used to store values for use in a flow or mule app. The values that can be stored in variables are objects, strings, numbers, messages, message attributes, message payloads, and dataweave expressions.

Mule 3 has 3 different types of variables:

  1. Flow variable

  2. Session variable

  3. Record variable

However, in Mule 4, the record variable is not there.

The scope of a flow variable is within a flow or subflow until there is no transport barrier like HTTP, VM, etc. Session variable scope is throughout the app even though there is a transport barrier.

In this article, we will see how these variables are processed in an async scope of a flow.

If you add an Async Flow in parent flow, the async flow runs in parallel along with the parent flow. The flow variable defined in the parent flow is passed to Async Flow and beyond it to the remaining flow. However, the changes in the variable inside the Async flow are not applicable or visible to the flow outside of the Async flow.

Async Flows don't send any response to parent flow. Let us see this in the example below:

Image title

In the example, the parent flow named AsyncExampleFlow calls the SubFlow named AsyncSubFlow using a flow reference component where the variable named number is set with value two.

From subflow (AsyncSubFlow) through VM connector, Flow2 is getting called since the flow variable crossed the transport barrier and the value of the number variable set in subflow is not applicable to Flow2.

The variable number is not accessible in the first logger in Flow2.

In Flow2, the number variable value is set as three. In the log, the value is printed as three from the second logger.

Once the subflow execution completes from parent flow, the async scope flow gets executed along with the parent flow. Even though inside the async flow the number variable value is set as four, the response we get through the payload is two. Since the value of the variable is set as two in the subflow, the same is returned to the parent flow.

The async scope does not return the response of flow variable to the parent flow as it is also executing along with the parent flow.

In the above example, instead of flow variable, if we use a session variable, the response will be three since the session variable scope is available outside of the transport barrier as well.

I hope you now understand flow variables in async flows a bit better. Please leave your feedback.

Flow (web browser) Session (web analytics) MuleSoft

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • The Quest for REST
  • Upgrade Guide To Spring Data Elasticsearch 5.0
  • Load Balancing Pattern
  • Key Considerations When Implementing Virtual Kubernetes Clusters

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: