With batch processing comes the ability to set, remove and reference variables associated to individual records. Serialized and persisting only through the Process phase, a record variable stores information at the record level, rather than the flow or session level. For example, you can use recordVars to capture whether or not a customer contact – as a record – already exists in a database.
During the Process phase, the record is the message payload. As such, you may wish to use MEL expressions in message processors within a batch step to replace or manipulate the payload during processing. However, where you don’t want to touch the payload, you can use record variables to persist information between batch steps. There are two way you can set record variables within batch steps in a batch job:
Set a Record Variable message processor in one of the batch steps in your batch job, setting the Operation to Set Record Variable. View full details of the message processor’s attributes.
<batch:set-record-variable doc:name="Record Variable" variableName="age" value="#[payload.age]"/>
Use a MEL expression to add a new
recordVarsto records within a batch step.
During the Process phase of batch processing, use the Record Variable message processor to remove an existing
recordVars from records, setting the Operation to Remove Record Variable. View full details of the message processor’s http://www.mulesoft.org/documentation/display/current/Batch+Processing+Reference#BatchProcessingReference-ElementsandAttributes[attributes].
1 <batch:remove-record-variable doc:name="Record Variable" variableName="age" />
For example, say you conditionally set a record variable on records in the first batch step – maybe wherever the value of
Maine, you set a recordVars for "qualified".
1 batch:set-record-variable-transformer doc:name="Record Variable" variableName="qualified" value="#[message.payload.state['ME']]"/>
In the second batch step, you can use an accept expression to instruct the step to process only qualified records, as shown below.