Nav
You are viewing an older version of this topic. To go to a different version, use the version menu at the upper-right. +

Batch Job Instance ID

Users of Batch processing frequently need the ability to determine a Batch job’s instance ID during the execution phases of a Batch job.

Note: This feature only works in Mule 3.7 and newer.

The Batch job instance ID is useful to:

  • Pass the local job instance ID to an external system for referencing and managing data

  • Improve the job’s custom logging

  • Send email or SMS notifications for meaningful events

Example

Mule exposes the batch job instance ID through a flow variable of key batchJobInstanceId. That flow variable is available at the beginning of the input phase. The flow variable is also available in every step and in the on-complete phase.

Example job:

batch

As you see this job is pretty simple. In each of its phases, the job invokes a sub­flow which logs the output of the following MEL expression:


         
      
1
#[flowVars[‘batchJobInstanceId’]]

The log output produces the following – note the second block where the Job Instance ID appears as: 

org.mule.api.processor.LoggerMessageProcessor: Job Instance Id is: ba01e1a0-f5c7-11e4-9414-10ddb1daeb6d


         
      
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
INFO 2015-05-08 18:18:09,599 [[batch].HTTP_Listener_Configuration.worker.01] com.mulesoft.module.batch.engine.DefaultBatchEngine: Starting input phase

INFO 2015-05-08 18:18:09,603 [[batch].HTTP_Listener_Configuration.worker.01] org.mule.api.processor.LoggerMessageProcessor: Job Instance Id is: ba01e1a0-f5c7-11e4-9414-10ddb1daeb6d

INFO 2015-05-08 18:18:09,603 [[batch].HTTP_Listener_Configuration.worker.01] com.mulesoft.module.batch.engine.DefaultBatchEngine: Input phase completed

INFO 2015-05-08 18:18:09,608 [[batch].HTTP_Listener_Configuration.worker.01] com.mulesoft.module.batch.engine.queue.BatchQueueLoader: Starting loading phase for instance 'ba01e1a0-f5c7-11e4-9414-10ddb1daeb6d' of job 'batchBatch'

INFO 2015-05-08 18:18:09,610 [[batch].HTTP_Listener_Configuration.worker.01] com.mulesoft.module.batch.engine.queue.BatchQueueLoader: Finished loading phase for instance ba01e1a0-f5c7-11e4-9414-10ddb1daeb6d of job batchBatch. 1 records were loaded

INFO 2015-05-08 18:18:09,615 [[batch].HTTP_Listener_Configuration.worker.01] com.mulesoft.module.batch.engine.DefaultBatchEngine: Started execution of instance 'ba01e1a0-f5c7-11e4-9414-10ddb1daeb6d' of job 'batchBatch'

INFO 2015-05-08 18:18:09,624 [batch-job-batchBatch-work-manager.01] org.mule.api.processor.LoggerMessageProcessor: Job Instance Id is: ba01e1a0-f5c7-11e4-9414-10ddb1daeb6d

INFO 2015-05-08 18:18:09,643 [batch-job-batchBatch-work-manager.01] com.mulesoft.module.batch.engine.DefaultBatchEngine: Starting execution of onComplete phase for instance ba01e1a0-f5c7-11e4-9414-10ddb1daeb6d of job batchBatch

INFO 2015-05-08 18:18:09,644 [batch-job-batchBatch-work-manager.01] org.mule.api.processor.LoggerMessageProcessor: Job Instance Id is: ba01e1a0-f5c7-11e4-9414-10ddb1daeb6d

INFO 2015-05-08 18:18:09,644 [batch-job-batchBatch-work-manager.01] com.mulesoft.module.batch.engine.DefaultBatchEngine: Finished execution of onComplete phase for instance ba01e1a0-f5c7-11e4-9414-10ddb1daeb6d of job batchBatch

INFO 2015-05-08 18:18:09,644 [batch-job-batchBatch-work-manager.01] com.mulesoft.module.batch.engine.DefaultBatchEngine: Finished execution for instance 'ba01e1a0-f5c7-11e4-9414-10ddb1daeb6d' of job 'batchBatch'. Total Records processed: 1. Successful records: 1. Failed Records: 0

In this topic: