Free MuleSoft CONNECT Keynote & Expo Pass Available!

Register now+
Nav

About The Fixed Size Batch Aggregator

You can configure a batch aggregator scope to process fixed-size groups of records inside a batch aggregator scope.

You can configure the batch aggregator scope to upsert, for example, 100 records at a time.


         
      
1
2
3
4
5
6
7
8
9
<batch:job jobName="batchJob">
        <batch:process-records >
                <batch:step name="batchStep">
                        <batch:aggregator size="100">
                                ...
                        </batch:aggregator>
                </batch:step>
        </batch:process-records>
</batch:job>

When using a fixed-size aggregator, you can replace, change, or store the payload and variable data of each record.

By adding a foreach scope you can iterate trough a fixed-size aggregator block, and use the Groovy and the scripting module to modify the payload and create a variable for each collected record.
You can sequentially go over each record’s data and persistently store each record’s payload and variables. This method of accessing records within the batch aggregator is called sequential access.


         
      
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<batch:job jobName="batchJob">
        <batch:process-records>
                <batch:step name="batchStep">
                        <batch:aggregator doc:name="batchAggregator" size="10">
                                <foreach doc:name="For Each">
                                        <script:execute engine="groovy">
                                    <script:code>
                                                vars['marco'] = 'polo'
                                                        vars['record'].payload = 'foo'
                                    </script:code> </script:execute>
                                </foreach> </batch:aggregator>
                </batch:step> </batch:process-records>
</batch:job>

The sequential access method assumes that:

  1. The aggregator size matches the amount of aggregated records.

  2. There is a direct correlation between the aggregated records and the items in the list.

You can also access random records by specifying the iteration number of the foreach. This saves you the need to iterate through all records. The foreach scope exposes a records variable. This variable is an immutable list used by foreach to keep track of the iteration, and provides a random access list that is accessible across the batch aggregator.

You can carry out the same result as the example above by specifying an arbitrary index number for the records list instead of sequentially access each record. You can, for example, create a variable and modify the payload of the first record as shown below.


         
      
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<batch:job jobName="batchJob">
        <batch:process-records>
                <batch:step name="batchStep">
                        <batch:aggregator doc:name="batchAggregator" size="10">
                                <foreach doc:name="For Each">
                                        <script:execute engine="groovy">
                                    <script:code>
                                        records[0].vars['marco'] = 'polo'
                                                records[0].vars['record'].payload = 'foo'
                                    </script:code> </script:execute>
                                </foreach> </batch:aggregator>
                </batch:step> </batch:process-records>
</batch:job>

Using random access, you can change a record’s payload at any index position in the commit block.

In this topic: