Batch Processing in Mule

Batch processing is useful when you want to process records in bulk

Here use case is to upload the student's records in bulk from CSV file to oracle database.



1. Create a mule project in studio and add Batch element to the canvas batch processing has three phases Input, Load and dispatch, Process, and OnComplete

  • Input: It is an optional part of batch process configuration. This is the initiator for the batch process to start, it can be file adaptor which can poll for file or poll component which will look for any records from a database or inbound connectors. During this phase, no splitting or aggregation is performed by mule. it just acts upon the message payload. you can perform any transforms before the message gets feed into process phase.
  • Load and Dispatch: This is the implicit phase of batch processing and you don't need to configure anything. It creates a batch job instance, This is a phase where mule splits the message into the record by collection splitter, Mule creates a persistent queue and associates it to the new batch job instance.
  • Process: This is the required phase of the batch job Mule begins asynchronous processing of the records in the batch within this required phase, each record moves through the message processors in the first batch step, then is sent back to queue before sending into next batch steps and so on until every record has passed through every batch step. Each record keeps track of the stage it has been processed through while it sits in the queue. Batch job instance does not wait for all its queued records to finish processing in one batch step 
  • On complete: This is the final phase of batch processing, you can configure the steps to send reports of how many records are processed successfully /failed.
2. In the input phase, add a file connector to read a student.csv file
student.csv

Id,Name,Course
1,Gopi,Java
2,Kar,Testing

3. Add TransformMessage processor to convert the csv format to collection list of students records.

4. Add the database connector in batch step to insert records into students table.



you can download the project from github

Comments

Popular posts from this blog

RingCentral - How to use ringcentral Webhook features for events in Java

Hello world project in Spring

Building and unit testing Mule project with Maven