Batch Module: Obtaining the job instance id in Mule 3.7

Facebooktwittergoogle_plusredditpinterestlinkedinmail

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.

Example

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:

batch

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!

Thanks!

Facebooktwittergoogle_plusredditpinterestlinkedinmail

Mariano Gonzalez

I first started working on the IT industry in 2001 and I've been working as software architect and team leader since 2006, mainly on BPM/ERP applications for industries in the agriculture, energy, government, IT, telecom and content management industries, serving roles of Team Leader and software architect. Since 2011, I also started to specialize in SaaS applications and integration on the Cloud. I have a strong orientation to both, software architecturing and design as for team management, I'm constantly looking for challenges that allows me to develop and increase my social and technical skills

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>