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

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

SBOMs are essential to circumventing software supply chain attacks, and they provide visibility into various software components.

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

  • One Checkbox to Cloud: Migrating from Tosca DEX Agents to E2G
  • Event Storming Workshops: A Closer Look at Different Approaches
  • Reducing Hallucinations Using Prompt Engineering and RAG
  • Continuous Quality Engineering: The Convergence of CI/CD, Chaos Testing, and AI-Powered Test Orchestration
  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

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
  • [email protected]

Let's be friends: