Variables in Batch Job

 

Variables in Batch Job – In Mule 4 Batch processing if a variable is defined in batch step then it will be tied to the record in process and will be present throughout the record processing i.e. throughout all consecutive batch steps. Sequence is followed so variable declared in Batch Step will only be available in succeeding Batch Steps

In below table we can see the example where if Variable is defined or updated in any of the batch step then it will be available throughout the consecutive Batch Steps

Batch Step 1 Batch Step 2 Batch Step 3 Batch Step 4
Record R1 R1 R1 R1
Variable V1 = 10, V2 = 20 V1 = 10, updated V2 = 30 updated V1 = 20, V2 = 30 V1 = 20, V2 = 30

 

For POC we will initialize the variable in first Batch Step and Log the values in later Batch Steps

Initialize orderId to Order ID in payload

Variables in Batch Job

 

Let’s print the value in succeeding Batch Steps

 

In last Batch Step

Variables in Batch Job

 

If we run the application for 3 records then we can see the logs getting printed with correct Order ID

INFO  2020-06-08 12:59:59,774 [[MuleRuntime].io.05: [batch-job-sample].batch-job-batch-job-sample_Batch_Job-work-manager @7729c08a] [event: dbfee500-a959-11ea-9812-9aaf65ed66d8] 
org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 669165933 - Processed
INFO  2020-06-08 12:59:59,777 [[MuleRuntime].io.05: [batch-job-sample].batch-job-batch-job-sample_Batch_Job-work-manager @7729c08a] [event: dbfee500-a959-11ea-9812-9aaf65ed66d8] 
org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 963881480 - Processed
INFO  2020-06-08 12:59:59,813 [[MuleRuntime].io.05: [batch-job-sample].batch-job-batch-job-sample_Batch_Job-work-manager @7729c08a] [event: dbfee500-a959-11ea-9812-9aaf65ed66d8] com.mulesoft.mule.runtime.module.batch.internal.DefaultBatchStep: Step Batch_Step_Processed_Records finished processing all records for instance dbff0c10-a959-11ea-9812-9aaf65ed66d8 of job batch-job-sample_Batch_Job
INFO  2020-06-08 12:59:59,816 [[MuleRuntime].io.08: [batch-job-sample].batch-job-batch-job-sample_Batch_Job-work-manager @7729c08a] [event: dbfee500-a959-11ea-9812-9aaf65ed66d8] 
org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 341417157 - Failed
INFO  2020-06-08 12:59:59,817 [[MuleRuntime].io.08: [batch-job-sample].batch-job-batch-job-sample_Batch_Job-work-manager @7729c08a] [event: dbfee500-a959-11ea-9812-9aaf65ed66d8] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: failed record found Region,Country,Item Type,Sales Channel,Order Priority,Order Date,Order ID,Ship Date,Units Sold,Unit Price,Unit Cost,Total Revenue,Total Cost,Total Profit
Europe,Russia,Office Supplies,Offline,L,5/2/2014,341417157,5/8/2014,1779,651.21,524.96,1158502.59,933903.84,224598.75

 

Sample mule application: batch-job-sample-variables

Sample CSV – Sample

 

  
Thank you for taking out time to read the above post. Hope you found it useful. In case of any questions, feel free to comment below. Also, if you are keen on knowing about a specific topic, happy to explore your recommendations as well.
 
For any latest updates or posts on our website, you can follow us on LinkedIn. Look forward to connecting with you there.


Share this:
Subscribe
Notify of
guest
2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Md imtiyaz
Md imtiyaz
1 year ago

Hi plz tell in batch job configuration I did not get

Edgar
Edgar
1 year ago

cool