Contact Us 1-800-596-4880

Using MEL with Batch Processing

Mule Runtime Engine versions 3.5, 3.6, and 3.7 reached End of Life on or before January 25, 2020. For more information, contact your Customer Success Manager to determine how you can migrate to the latest Mule version.

All of the functions and attributes below are usable within MEL expressions anywhere in Mule where the context makes sense.

These attributes can be referenced in any element inside or after your batch job:

Attribute Description

recordVars

Use to access record variables by name.

totalRecords

Total number of records in the batch.

loadedRecords

Number of records loaded in Loading phase.

processedRecords

Number of records processed at this point.

failedRecords

Number of records processed and failed in at least one step.

batchJobInstanceId

ID of the batch job instance

inputPhaseException

Exception object for exception in Input phase.

loadingPhaseException

Exception object for exception in Loading phase.

completePhaseException

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

isSuccessfulRecord()

Boolean function indicating processing status of record.

isFailedRecord()

Boolean function indicating processing status of record.

failedOnInputPhase()

Boolean function indicating whether or not batch processing failed at the Input phase.

failedOnLoadingPhase()

Boolean function indicating whether or not batch processing failed at Loading phase.

failedOnCompletePhase()

Boolean function indicating whether or not batch processing failed at Complete phase.

failureExceptionForStep()

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

getStepExceptions()

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.

getFirstException()

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.

getLastException()

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.

Example Use of A MEL Function in a Batch Job

For example, suppose you have a batch job with the following Batch Step:

batch+function1

Here you can add the following expression into the Set Payload transformer:

batch+function2

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