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

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Why and When to Use GraphQL
  • MuleSoft (Event-Based Process) With Enhanced Execution Engine
  • Low-Level Optimizations in ClickHouse: Utilizing Branch Prediction and SIMD To Speed Up Query Execution
  • Mastering Concurrency: An In-Depth Guide to Java's ExecutorService

Trending

  • Analyzing “java.lang.OutOfMemoryError: Failed to create a thread” Error
  • Enhancing Security With ZTNA in Hybrid and Multi-Cloud Deployments
  • Understanding and Mitigating IP Spoofing Attacks
  • Beyond Microservices: The Emerging Post-Monolith Architecture for 2025
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Mule Scatter-Gather Shallow Diving: Part I

Mule Scatter-Gather Shallow Diving: Part I

The Mule Scatter-Gather component can be used to solve typical message multicasting scenarios. The flow is pretty simple.

By 
Anupam Gogoi user avatar
Anupam Gogoi
·
Jan. 27, 17 · Opinion
Likes (1)
Comment
Save
Tweet
Share
4.9K Views

Join the DZone community and get the full member experience.

Join For Free

Let's assume that we have a common integration scenario. You are querying the price of an iPhone. The system should return you all possible prices of the iPhone, consulting various sites. This turns out to be a typical message multicasting scenario.

Mule Solution

To solve this kind of integration scenario, Mule provides an awesome component called Scatter-Gather. The most important points of this component are as follows.

Parallel Processing

The Scatter-Gather component can send messages to all the routes concurrently. It maintains a thread pool to concurrently execute the provided routes. Thus, the time needed to execute all routes is less, in contrast to its previous version, which executes the routes in a parallel fashion. This means that when a route is being processed the remaining routes must have to wait for its completion.

Error Handling

Each route executes in its own thread and thus, if an exception occurs, it does not prevent the execution of other routes that execute in their own threads. So, the final result may contain responses from the successful routes as well as from the failed ones. 

Configuration

By default, Scatter-Gather uses the default Mule implementation for aggregating messages. However, this behavior can be overridden by using the custom Java implementation. 

Getting Your Hands Dirty

In this post, I will try to explain the use of the Scatter-Gather component with a simple example.

The scenario is as follows: "Let's suppose we have two websites called "Wallmarty" and "Amazona" selling iPhones. Now, I want a list of the iPhones available in both sites in descending order of price."

Mock Services

I have created a mock service exposing the following two REST URLs:

  • http://localhost:9090/amazona?type=iphone.

  • http://localhost:9090/wallmarty?type=iphone.

Please download the JAR named market-0.0.1-SNAPSHOT.jar and execute it. Make sure that port 9090 is not being used on your machine. After running the service, you can verify the above-quoted links. 

Creating the Flow

Please find the complete source code here. I have created a simple flow named scatter-gather-example.xml .Here is a screenshot.

Flow Diagram

The flow is simple. The Scatter-Gather component simply gathers information from the sub-flows getWallmartyProductFlow and getAmazonaProductFlow and merges the information. The transformers simply transform the response based on some JSON schema and orders the output in descending order of price.

Simple Output

Here is the screenshot of a simple output.

[
  {
    "price": 185.5,
    "product_name": "IPhone6",
    "vendor": "www.wallmarty.com"
  },
  {
    "price": 186.5,
    "product_name": "IPhone5",
    "vendor": "www.wallmarty.com"
  },
  {
    "price": 187.5,
    "product_name": "IPhone6",
    "vendor": "www.amazona.com"
  },
  {
    "price": 188.5,
    "product_name": "IPhone6",
    "vendor": "www.amazona.com"
  },
  {
    "price": 188.5,
    "product_name": "IPhone5",
    "vendor": "www.amazona.com"
  },
  {
    "price": 188.5,
    "product_name": "IPhone6",
    "vendor": "www.amazona.com"
  },
  {
    "price": 189.5,
    "product_name": "IPhone6",
    "vendor": "www.wallmarty.com"
  },
  {
    "price": 189.5,
    "product_name": "IPhone6",
    "vendor": "www.wallmarty.com"
  },
  {
    "price": 189.5,
    "product_name": "IPhone6",
    "vendor": "www.amazona.com"
  },
  {
    "price": 190.5,
    "product_name": "IPhone5",
    "vendor": "www.wallmarty.com"
  },
  {
    "price": 190.5,
    "product_name": "IPhone6",
    "vendor": "www.wallmarty.com"
  },
  {
    "price": 190.5,
    "product_name": "IPhone6",
    "vendor": "www.amazona.com"
  },
  {
    "price": 191.5,
    "product_name": "IPhone5",
    "vendor": "www.wallmarty.com"
  },
  {
    "price": 191.5,
    "product_name": "IPhone5",
    "vendor": "www.amazona.com"
  },
  {
    "price": 194.5,
    "product_name": "IPhone6",
    "vendor": "www.wallmarty.com"
  },
  {
    "price": 194.5,
    "product_name": "IPhone5",
    "vendor": "www.wallmarty.com"
  },
  {
    "price": 194.5,
    "product_name": "IPhone6",
    "vendor": "www.amazona.com"
  },
  {
    "price": 194.5,
    "product_name": "IPhone5",
    "vendor": "www.amazona.com"
  },
  {
    "price": 450,
    "product_name": "Mac Pro",
    "vendor": "www.amazona.com"
  },
  {
    "price": 451,
    "product_name": "IPhone6",
    "vendor": "www.amazona.com"
  },
  {
    "price": 453,
    "product_name": "IPhone6",
    "vendor": "www.amazona.com"
  },
  {
    "price": 453,
    "product_name": "IPhone6",
    "vendor": "www.amazona.com"
  },
  {
    "price": 453,
    "product_name": "IPhone6",
    "vendor": "www.amazona.com"
  },
  {
    "price": 455,
    "product_name": "IPhone6",
    "vendor": "www.amazona.com"
  },
  {
    "price": 457,
    "product_name": "IPhone6",
    "vendor": "www.amazona.com"
  },
  {
    "price": 458,
    "product_name": "Mac Pro",
    "vendor": "www.amazona.com"
  },
  {
    "price": 458,
    "product_name": "Mac Pro",
    "vendor": "www.amazona.com"
  }
]

In the next post, I will try to explain the Scatter-Gather using custom aggregation strategy. 

Thread pool Flow (web browser) Implementation POST (HTTP) Integration Schema Execution (computing) Web Protocols

Opinions expressed by DZone contributors are their own.

Related

  • Why and When to Use GraphQL
  • MuleSoft (Event-Based Process) With Enhanced Execution Engine
  • Low-Level Optimizations in ClickHouse: Utilizing Branch Prediction and SIMD To Speed Up Query Execution
  • Mastering Concurrency: An In-Depth Guide to Java's ExecutorService

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!