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

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

Enterprise AI Trend Report: Gain insights on ethical AI, MLOps, generative AI, large language models, and much more.

2024 Cloud survey: Share your insights on microservices, containers, K8s, CI/CD, and DevOps (+ enter a $750 raffle!) for our Trend Reports.

PostgreSQL: Learn about the open-source RDBMS' advanced capabilities, core components, common commands and functions, and general DBA tasks.

AI Automation Essentials. Check out the latest Refcard on all things AI automation, including model training, data security, and more.

Related

  • Error Handling Inside Kumologica Subflow
  • Low Code Serverless Integration With Kafka
  • Vector Tutorial: Conducting Similarity Search in Enterprise Data
  • The Power of AI: Building a Robust Data Ecosystem for Enterprise Success

Trending

  • Securing Cloud Storage Access: Approach to Limiting Document Access Attempts
  • Secure Your API With JWT: Kong OpenID Connect
  • Maximizing Developer Efficiency and Productivity in 2024: A Personal Toolkit
  • Exploring the Frontiers of AI: The Emergence of LLM-4 Architectures

Flow Control in Mule 4

In this article, we will look into four different Flow control components provided in Mule. We will also cover various use cases.

By 
Karan Gupta user avatar
Karan Gupta
·
Feb. 13, 22 · Review
Like (3)
Save
Tweet
Share
11.6K Views

Join the DZone community and get the full member experience.

Join For Free

In Mule, Flow Controls helps you Route your input Mule Event into one or more separate flows based on the Flow control components you use. 

In this article, we'll discuss 4 of them that are listed below:

  • Choice
  • Scatter-Gather
  • Round-Robin
  • First Successful

Let's understand each of these components and their use case.

Choice

Choice Router works on the evaluation of the expression i.e., True or False. The Route for which the expression evaluates to be True, that route is executed.

It executes routes sequentially i.e. if for both route-1 and route-2 condition expression evaluates to be true, it will execute only route-1 because of its sequential nature and will not execute route-2.

The expression cannot be kept as blank and there is a default block that executes if none of the expressions evaluates to True.

Use Case

Consider you want to fetch the details of employees based on their department, you can make use of Choice Router. The First condition will fetch the employees from  the IT department, e.g., payload.Employee.Department == "IT", the Second condition will fetch the employees from the HR department, e.g., payload.Employee.Department == "HR". 

If a department other than this comes in the input then the Default route will be triggered.

Choice Component

Scatter-Gather

Unlike Choice router which takes only one route, Scatter-Gather sends the requested data to multiple routes concurrently.

It waits for all the routes to complete the execution and then aggregates the response from each route and forms a Single output message. The Output of this is application/java format and consists of payload and attributes.

One more point to note here is, if any one of the routes fails, then the entire Scatter-Gather process fails. So while using Scatter-Gather, error handling becomes very crucial.

The maximum time taken by Scatter-Gather to complete the execution is the max time taken by any route. For instance, if route-1 takes 5 secs and route-2 takes 10 secs then Scatter-Gather will take 10 secs to complete the execution.

Use Case

Suppose you need to club data for 2 different targets then instead of calling both of these targets sequentially, you can use Scatter-Gather. Below is a simple demo with the Scatter-Gather output.

Scatter-Gather Component

Aggregated Output

First Successful

First Successful is a router that iterates through each route in the router component until one of the routes executes successfully. If none of the routes in this router component give a success response then the router component throws an error response. 

So basically, the First Successful router sends the incoming data to route-1 and if this route fails, it then sends the same data to route-2. If this route gives success response then the First successful router will not execute any further routes and will complete the execution.

Use Case

You can use this router when you want to make a call to your application running on the secondary server if the application running on the primary server fails to respond. Below is a simple demo.

First Successful Component

Round Robin

This router iterates through all the routes in the router component in a specific order but it only routes to one of the routes each time it is executed. For example, it keeps track of the last route it selected for execution and will not execute the same route again consecutively.

Basically, this router works in a circular manner and whichever route executes first will not be executed in the next execution till all the other routes are executed at least once.

Use Case

This Router generally fits in scenarios where you want to balance the load i.e. distribute the load on each route. Below is the simple demo where the logger-1 route will execute first and in the immediate next iteration, the logger-2 will be executed and this sequence will continue.

Round Robin Component


Flow control (data) Flow (web browser) Use case Round-robin (document)

Opinions expressed by DZone contributors are their own.

Related

  • Error Handling Inside Kumologica Subflow
  • Low Code Serverless Integration With Kafka
  • Vector Tutorial: Conducting Similarity Search in Enterprise Data
  • The Power of AI: Building a Robust Data Ecosystem for Enterprise Success

Partner Resources


Comments

ABOUT US

  • About DZone
  • Send 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: