A popular request among users of the Batch module is the ability to grab the job instance id in any of a Batch job’s phases. Why is that useful? Well, there could be a number of useful scenarios:
If the batch communicates with an external system, it’s sometimes useful to pass the local job instance id for reference and management purposes
To improve the job’s custom logging
Some jobs might want to fire email or SMS notifications for meaningful events, having the job instance id in those messages is obviously helpful.
The id will be exposed throw a flow variable of key ‘batchJobInstanceId’. That flow variable will be available since the very beginning of the input phase. It will also be available on every step and in the on-complete phase. Let’s see an example job:
As you see this job is pretty simple. In all its phases, it invokes a sub-flow which logs the output of #[flowVars[‘batchJobInstanceId’]]. The log output that it produces is the following:
So that’s it. This is a small, easy to use improvement which I hope you’ll find useful. Have any other examples of how the job instance id can be useful? Please share!
MuleSoft provides the most widely used integration platform for connecting any application, data source or API, whether in the cloud or on-premises. With Anypoint Platform®, MuleSoft delivers a complete integration experience built on proven open source technology, eliminating the pain and cost of point-to-point integration. Anypoint Platform includes CloudHub™ iPaaS, Mule ESB™, and a unified solution for API management™, design and publishing.