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

  • How Power Automate Helps Analysts Send Alert Emails Faster and How AI Builder Takes It to the Next Level
  • 2 Hidden Bottlenecks in Large-Scale Azure Migrations
  • How to Create a Custom React Component in Vaadin Flow
  • Explore Salesforce OAuth Authorization Flows and Its Use Cases

Trending

  • Why We Chose Iceberg Over Delta After Evaluating Both at Scale
  • Self-Hosted Inference Doesn’t Have to Be a Nightmare: How to Use GPUStack
  • Optimizing High-Volume REST APIs Using Redis Caching and Spring Boot (With Load Testing Code)
  • What Nobody Tells You About Multimodal Data Pipelines for AI Training

Private vs. Sub Flow in Mule

This article briefly outlines the difference between private flows and subflows in Mule, and when each type is recommended.

By 
Anupam Gogoi user avatar
Anupam Gogoi
·
Aug. 02, 17 · Tutorial
Likes (6)
Comment
Save
Tweet
Share
36.8K Views

Join the DZone community and get the full member experience.

Join For Free

Mule has the concept of Private and Sub flows. In this article, both of them will be discussed.

Sub Flow

A subflow is a normal flow without any message source. Here is how it looks in XML configuration.

<sub-flow name="subFlow">
        <scripting:component doc:name="Groovy">
            <scripting:script engine="Groovy"><![CDATA[throw new Exception("Sub Flow Exception");]]></scripting:script>
        </scripting:component>
</sub-flow>

A subflow can be called by the flow-reference element of Mule. When the main flow (calling) calls the subflow using the flow-reference element, it passes the whole message structure (message properties, payload, attachments, etc) and the context (session, transaction, etc). In the same way, when the processing of the message is done in the subflow, the complete message and context are returned to the main calling flow. In other words, everything in the subflow behaves as if it were in the same flow. It's important to note that the message is executed in the same thread.

Usage

Subflows can be used when some block of code (components) can be reused across the application and you don't want to handle the exceptions of the subflow separately from the main calling flow.  

Private Flow

Private flows are same as standard flows without the message source. They can also be called using the flow-reference element. This is how it looks in XML configuration:

 <flow name="privateFlow" processingStrategy="synchronous">

 </flow>

Private flows are different from subflows in terms of Threading and Exception Handling. They have their own Exception Handling. The exception will be trapped by the local Exception Handling and it will not be propagated to the main flow. It means that if an exception occurs in a Private flow and it is handled properly when the call goes back to the main calling flow, the next message processors continue executing. 

Private flows also receive the same message structure from the main calling flow. But Private flows create a new execution context.

Conclusion 

To summarize, subflow is always recommended, except when the exception needs to be handled in a separate exception handling flow different from the main flow or if you are implementing an asynchronous pattern.

Flow (web browser)

Opinions expressed by DZone contributors are their own.

Related

  • How Power Automate Helps Analysts Send Alert Emails Faster and How AI Builder Takes It to the Next Level
  • 2 Hidden Bottlenecks in Large-Scale Azure Migrations
  • How to Create a Custom React Component in Vaadin Flow
  • Explore Salesforce OAuth Authorization Flows and Its Use Cases

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