Author: Swetha Bokka
Let’s discuss Batch Processing.
MuleSoft allows you to process messages as a batch which can be achieved by batch scope. Batch scope in a mule application can divide the input payload into individual records, performs actions on these individual records, and then sends the processed data to target systems.
Batch job divides payload as 100 records a batch, like that it will process 16 threads at a time.
Batch has three phases in Mule 4.
Load And Dispatch:
It will create job instances, convert payload into collection of records and then split the collection into individual records for processing.
In this phase, it processes all individual records asynchronously. Batch step in this phase allows you to filter records.
We can also use batch aggregator processor to aggregate records into groups. For example, if you want to process 10 as one group, you can set the aggregate processor size as 10.
The last and optional phase gives a summary of the payload. It will give us how many records are processed, and how many failed.
Let’s see an example on Batch Processing.
Here, I am inserting the records into Salesforce by using batch processing. I have created Employee custom object in the Salesforce, then I am storing the records through mule by using batch processing.
Now, I am going to construct one flow in anypoint studio by taking a http listener, transform message component for field mapping with respect to Salesforce.
Drag and drop batch job from mule pallet and default batch job size is 100. Create single component from Salesforce connector to store the single record in Salesforce.
Configure the create single component with the sales force configuration and type as name of the object created in Salesforce (Employee).
Finally, deploy the project locally and test from postman. The batch job will send payload as asynchronously, one by one records to batch step, it will apply necessary actions on records, and it will store data in the Salesforce. See below processed data:
Drag and drop the set payload component from mulepallete to oncomplete phase of batch job. Then we can observe summary of the records, that means total records processed, successful records and failed records. See below screenshot:
This is the way in which batch processing works in Mule 4.