<batch:step name="Batch_Step">
<file:outbound-endpoint path="output" outputPattern="test.file" connector-ref="File" responseTimeout="10000" />
</batch:step>
Using MEL with Batch Processing
All of the functions and attributes below are usable within MEL expressions anywhere in Mule where the context makes sense.
MEL Attributes Related to Batch Jobs
These attributes can be referenced in any element inside or after your batch job:
Attribute | Description |
---|---|
|
Use to access record variables by name. |
|
Total number of records in the batch. |
|
Number of records loaded in Loading phase. |
|
Number of records processed at this point. |
|
Number of records processed and failed in at least one step. |
|
ID of the batch job instance |
|
Exception object for exception in Input phase. |
|
Exception object for exception in Loading phase. |
|
Exception object for exception in Complete phase. |
MEL Functions that Involve Batch Jobs
These functions can be used anywhere in your batch jobs, in any component that supports MEL expressions.
Function |
Description |
|
Boolean function indicating processing status of record. |
|
Boolean function indicating processing status of record. |
|
Boolean function indicating whether or not batch processing failed at the Input phase. |
|
Boolean function indicating whether or not batch processing failed at Loading phase. |
|
Boolean function indicating whether or not batch processing failed at Complete phase. |
|
Receives the name of a step as a String argument. If the current record threw exception on that step, then it returns the actual Exception object. Otherwise it returns null |
|
Returns a java Map<String, Exception> in which the keys are the name of a batch step in which the current record has failed and the value is the exception object itself. If the record hasn’t failed in any step, this Map will be empty, not null. Also, the Map contains no entries for steps in which the record hasn’t failed. |
|
Returns the Exception object for the very first step in which the current record has failed. If the record hasn’t failed in any step, then it returns null. |
|
Returns the Exception object for the last step in which the current record has failed. If the record hasn’t failed in any step, then it returns null. |
These MEL expressions evaluate batch step failures. Consider that failed asynchronous processes inside your batch step would not be considered as step failures by the runtime.
For example, if you have this batch step:
Because the file outbound endpoint is one-way, the message is dispatched and the batch step continues processing. So no step failure would be recorded by the runtime.
This would mean that the MEL function isFailedRecord()
would still return false, even if the outbound endpoint inside the batch step fails.
You can force the runtime to record the outbound-endpoint failure as a batch step failure by referencing the outbound endpoint as a synchronous process:
<batch:step name="Batch_Step">
<logger message=" #[server.dateTime]: payload is: #[payload]" level="INFO" category="BATCH_STEP_BEGIN" />
<flow-ref name="create-file" />
</batch:step>
<flow name="create-file" processingStrategy="synchronous">
<file:outbound-endpoint path="src/test/resources/output" outputPattern="test.file" connector-ref="File" responseTimeout="10000" />
</flow>
Or by enclosing the asynchronous process inside a transactional scope:
<batch:step name="Batch_Step">
<logger message=" #[server.dateTime]: payload is: #[payload]" level="INFO" category="BATCH_STEP_BEGIN" />
<transactional action="ALWAYS_BEGIN" doc:name="Transactional">
<file:outbound-endpoint path="src/test/resources/output" outputPattern="test.file" connector-ref="File" responseTimeout="10000" />
</transactional>
</batch:step>
Example Use of A MEL Function in a Batch Job
For example, suppose you have a batch job with the following Batch Step:
Here you can add the following expression into the Set Payload transformer:
In this case, this expression will return a Java Map for the current record where the key is the name of the batch step and the value is the exception object. This expression will of course only evaluate batch steps through which the current record has already passed, it can’t evaluate any batch steps that may come after it.
See Also
-
Read a Blog Post about handling errors with Batch
-
Read more about using Mule Expression Language (MEL)in your application