For BE/B.Tech/BCA/MCA/ME/M.Tech Major/Minor Project for CS/IT branch at minimum price Text Message @ 9424820157

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="http://www.mulesoft.org/schema/mule/quartz" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:batch="http://www.mulesoft.org/schema/mule/batch" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/batch http://www.mulesoft.org/schema/mule/batch/current/mule-batch.xsd
http://www.mulesoft.org/schema/mule/quartz http://www.mulesoft.org/schema/mule/quartz/current/mule-quartz.xsd">
    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" 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"/>
    </flow>
    <batch:job name="test_batchprocessBatch">
        <batch:process-records>
            <batch:step name="Batch_Step">
                <logger message="#[payload]" level="INFO" doc:name="Logger"/>
            </batch:step>
            <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"/>
                </batch:commit>
            </batch:step>
        </batch:process-records>
        <batch:on-complete>
            <logger message="#[payload]" level="INFO" doc:name="Logger"/>
        </batch:on-complete>
    </batch:job>

</mule>





Please go through below tutorials:


Mule 4 Tutorials

DEPLOY TO CLOUDHUB C4E CLIENT ID ENFORCEMENT CUSTOM POLICY RABBIT MQ INTEGRATION
XML TO JSON WEBSERVICE CONSUMER VM CONNECTOR VALIDATION UNTIL SUCCESSFUL
SUB FLOW SET & REMOVE VARIABLE TRANSACTION ID SCATTER GATHER ROUND ROBIN
CONSUME REST WEBSERVICE CRUD OPERATIONS PARSE TEMPLATE OBJECT TO JSON LOAD STATIC RESOURCE
JSON TO XML INVOKE IDEMPOTENT FILTER FOR EACH FLAT TO JSON
FIXWIDTH TO JSON FIRST SUCCESSFUL FILE OPERATIONS EXECUTE ERROR HANDLING
EMAIL FUNCTIONALITY DYNAMIC EVALUATE CUSTOM BUSINESS EVENT CSV TO JSON COPYBOOK TO JSON
CHOICE ASYNC

Widely used Connectors in Mule 3

CMIS JETTY VM CONNECTOR SALESFORCE POP3
JMS TCP/IP WEBSERVICE CONSUMER QUARTZ MONGO DB
FILE CONNECTOR DATABASE CONNECTOR


Widely used Scopes in Mule 3

SUB FLOW REQUEST REPLY PROCESSOR CHAIN FOR EACH CACHE
ASYNC TCP/IP COMPOSITE SOURCE POLL UNTIL SUCCESSFUL
TRANSACTIONAL FLOW

Widely used Components in Mule 3

EXPRESSION CXF SCRIPT RUBY PYTHON
JAVASCRIPT JAVA INVOKE CUSTOM BUSINESS EVENT GROOVY
ECHO LOGGER


Widely used Transformers in Mule 3

MONGO DB XSLT TRANSFORMER REFERENCE SCRIPT RUBY
PYTHON MESSAGE PROPERTIES JAVA TRANSFORMER GZIP COMPRESS/UNCOMPRESS GROOVY
EXPRESSION DOM TO XML STRING VALIDATION COMBINE COLLECTIONS BYTE ARRAY TO STRING
ATTACHMENT TRANSFORMER FILE TO STRING XML TO DOM APPEND STRING JAVASCRIPT
JSON TO JAVA COPYBOOK TO JSON MAP TO JSON JSON TO XML FLATFILE TO JSON
FIXWIDTH TO JSON CSV TO JSON


Widely used Filters in Mule 3

WILDCARD SCHEMA VALIDATION REGEX PAYLOAD OR
NOT MESSAGE PROPERTY MESSAGE IDEMPOTENT FILTER REFERNCE
EXPRESSION EXCEPTION CUSTOM AND


Exception Strategy in Mule 3

REFERENCE EXCEPTION STRATEGY CUSTOM EXCEPTION STRATEGY CHOICE EXCEPTION STRATEGY CATCH EXCEPTION STRATEGY GLOBAL EXCEPTION STRATEGY


Flow Control in Mule 3

CHOICE COLLECTION AGGREGATOR COLLECTION SPLITTER CUSTOM AGGREGATOR FIRST SUCCESSFUL
MESSAGE CHUNK AGGREGATOR MESSAGE CHUNK SPLITTER RESEQUENCER ROUND ROBIN SOAP ROUTER