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
Let’s print the value in succeeding Batch Steps
In last Batch Step
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
Hi plz tell in batch job configuration I did not get
cool