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
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Jakarta Faces Flow Scope: Managing Multi-Step UX Without Session State
  • Error Handling Wikipedia in MuleSoft
  • MDC Logging With MuleSoft Runtime 4.4
  • MuleSoft Integration With RabbitMQ

Trending

  • Running a Self-Hosted WAF in Production: Practical Lessons From SafeLine
  • The SDLC After AI
  • Adding Graph Retrieval to a RAG Pipeline With Python
  • Testing Java and Spring Applications With Kotlin: Low-Risk to Adoption

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  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.

By 
Radhika A
·
Jan. 16, 19 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
22.7K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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.

Related

  • Jakarta Faces Flow Scope: Managing Multi-Step UX Without Session State
  • Error Handling Wikipedia in MuleSoft
  • MDC Logging With MuleSoft Runtime 4.4
  • MuleSoft Integration With RabbitMQ

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • 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