Batch Processing in Mule | Batch Processing Example

Batch Processing in Mule | Batch Processing Example

Mule allows you to process messages in batches.It splits the large messages into individual records that are processed asynchronously within batch jobs.Within an application, you can initiate a batch job scope, which is a block of code that splits messages into individual records, performs actions upon each record, then reports on the results and potentially pushes the processed output to other systems or queues.

For example, you can use batch processing when :

1.Synchronizing data sets between business applications, such as syncing contacts between NetSuite and Salesforce.

2.Extracting, transforming and loading (ETL) information into a target system, such as uploading data from a flat file (CSV) to Hadoop.

3.Handling large quantities of incoming data from an API into a legacy system.

Batch processing has four stages : 

Input Phase: This is an optional part of the batch job that can be used to retrieve the source data using any message source or inbound connector. It also comprises of message processors to transform the source data before it is ready for processing.

Load and Dispatch: In this phase, the payload generated in the Input phase or provided to the batch from the caller flow is turned into a collection of records. It also creates a job instance for processing records. The collection is then sent through the collection-splitter to queue individual records for processing.

Process: This is the required phase where the actual processing of every record occurs asynchronously.

Each record from the input queue is processed through the first step and sent back to the queue after processing of the first step completes.

Records that are processed in the first step are then passed through the second step and sent back to the queue after processing of the second step completes.
Mule continues this until all records are passed through each step.At the step level, you can also specify what type of records each step should accept.

Processing of records through the next step does not wait for the previous step to finish processing all records. Mule manages the state of each record while it moves back and forth between the queue and steps.

On Complete: In this final but optional phase, It holds information such as the number of records loaded, processed, failed, succeeded.

flow of batch processing : 

Batch Execute : It is a mule component which accumulates records into chunks to process bulk upserts to external source or service.

In our example it calls the batch flow test_batchprocessBatch

Batch Execute configuration : 

All loggers are configured with #[payload]

Batch Commit scope configuration : 

URL : http://localhost:8085/api/batch Method : POST

Input :

Output :

Logger output :

XML project code : 

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:quartz="" xmlns:json="" xmlns:http="" xmlns:batch="" xmlns="" xmlns:doc=""
    <http:listener-config name="HTTP_Listener_Configuration" host="" port="8085" basePath="/api" doc:name="HTTP Listener Configuration"/>
    <quartz:connector name="Quartz" validateConnections="true" doc:name="Quartz"/>
    <flow name="test_batchprocessFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/batch" doc:name="HTTP"/>
        <byte-array-to-object-transformer returnClass="java.lang.Object" doc:name="Byte Array to Object"/>
        <json:object-to-json-transformer doc:name="Object to JSON"/>
        <json:json-to-object-transformer returnClass="java.util.ArrayList" doc:name="JSON to Object"/>
       <batch:execute name="test_batchprocessBatch" doc:name="test_batchprocessBatch"/>
        <json:object-to-json-transformer doc:name="Object to JSON"/>
    <batch:job name="test_batchprocessBatch">
            <batch:step name="Batch_Step">
                <logger message="#[payload]" level="INFO" doc:name="Logger"/>
            <batch:step name="Batch_Step1">
                <logger message="#[payload]" level="INFO" doc:name="Logger"/>
                <batch:commit size="2" doc:name="Batch Commit">
                    <logger message="#[payload]" level="INFO" doc:name="Logger"/>
            <logger message="#[payload]" level="INFO" doc:name="Logger"/>


© 2020

Share on :

Mule 4:

XML to JSON in mule 4 Web service consumer VM Validation in Mule 4 Until Successful
Sub flow Set Variable & Remove Variable Set Transaction ID Scatter Gather Round Robin
Consume Restful Service CRUD in Mule 4 Parse Template Object to JSON Load Static Resource
JSON to XML Invoke Idempotent Filter ForEach Flat file to JSON
Fixwidth to JSON First Successful File Execute Error Handling
Email Dynamic Evaluate Custom Business Event CSV to JSON Copybook to JSON
Choice Router Async RabbitMQ

Mule 3:

Database Connector Async CXF Attachement XSLT
Mongo DB Cache scope Custom Business Event Gzip Compress Expression
SMTP For Each Expression Javascript Filter Reference
Salesforce Message Enricher Groovy Parse Template Idempotent
VM Poll Invoke Ruby Message
Webservice consumer Python Transformer reference Message Property Not
Collection Aggregator First Sucessful Catch Exception Strategy Reference Exception Strategy Or
Choice Message Chunk Aggregator Choice Exception Strategy Global Exception Strategy Schema Validation
Custom Aggregator Scatter Gather Custom Exception Strategy Batch Processing MEL
M Unit RAML Map Operator API Mocking Dataweave