
Aggregator Module in Mule 4
Understanding the Aggregator Module in Mule 4
The Aggregator module in Mule 4 enables the collection of data based on predefined conditions. This guide will focus on demonstrating different types of aggregators: Size-Based Aggregator, Time-Based Aggregator, and Group-Based Aggregator.
Types of Aggregators in Mule 4
Size-Based Aggregator – Accumulates data until a specified number of records is reached.
Time-Based Aggregator – Aggregates data until a predefined time interval elapses.
Group-Based Aggregator – Collects data based on a grouping parameter, such as a company name, allowing the system to aggregate employee records per company.
1. Implementing a Size-Based Aggregator
To illustrate the Size-Based Aggregator, we will create a sample Mule application in Anypoint Studio.
Step 1: Adding the Aggregator Module
Drag and drop the Size-Based Aggregator from the Mule Palette.
If the module is missing, add it from Anypoint Exchange.
Step 2: Configuring an HTTP Listener
Set up an HTTP Listener to trigger the request.
While real-world scenarios may involve data ingestion from JMS Queues, Anypoint MQ, or Database Tables, for this Proof of Concept (POC), we will trigger the request five times.
Step 3: Defining Aggregation Parameters
Assign a name to the aggregator.
Set the batch size to 5 to accumulate five payloads before processing.
Step 4: Listening for Aggregated Data
Drag and drop an Aggregator Listener from the Mule Palette.
This component listens for the aggregated data and processes it.
Transform the collected payload into JSON format and log the output.
Step 5: Executing the Aggregator
Deploy the project and send five requests with different payloads.
Once the batch size reaches five, the aggregator processes and logs the combined payload as an array of employee records.
Sample Aggregated Output in Logs
2. Implementing a Time-Based Aggregator
The Time-Based Aggregator collects elements within a specified time window.
Steps to Implement
Set up an HTTP Listener to trigger the request.
Drag and drop the Time-Based Aggregator module and configure the required parameters.
Deploy the application and send multiple requests using Postman.
Observe that only six payloads are processed within the specified time window.
3. Implementing a Group-Based Aggregator
The Group-Based Aggregator assigns incoming data to specific groups based on a defined Group ID.
Steps to Implement
Set up an HTTP Listener to trigger the request.
Set up a Group-Based Aggregator flow and configure the required parameters.
Send requests via Postman
Review the logs to verify that data is grouped accordingly.
Conclusion
The Aggregator module in Mule 4 simplifies data processing by accumulating records based on defined conditions. This tutorial demonstrated Size-Based, Time-Based, and Group-Based Aggregators, all of which can be leveraged to optimize data collection and processing workflows in MuleSoft integrations.