mule custom aggregator

Post on 16-Apr-2017

142 Views

Category:

Software

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

CUSTOM AGGREGATOR

2

Scatter-Gather

• Scatter Gather is a mule routing strategy that may sends the same payload and execute different process asynchronously.

• By default, all results are gathered into a list of objects that can be used when needed.

3

Aggregation• If one did not specify a custom strategy, mule

provide a default one that populates all results into one single collection

• But sometimes, a need for custom aggregation is needed.

4

Custom AggregatorCreating custom aggregator is pretty simple.

1. Create a class that implements the following interface

org.mule.api.routing.AggregationContext

5

Custom Aggregator

2. Override and create your own implementation of the method

MuleEvent aggregate(AggregationContext context) throws MuleException

6

Custom Aggregator

One must understand the method and parameters that got overridden in order to create proper implementation.

aggregate(AggregationContext context)

7

Custom Aggregator

One must understand the method and parameters that got overridden in order to create proper implementation.

aggregate(AggregationContext context)

8

Custom AggregatorThere are 2 key factor that needs to understand under the parameter context.

1. The first one is the ‘events’ and2. The second one is ‘original event’.

9

Custom AggregatorContext ‘events’ defines a collection of events that gathered from one or multiple routes through scatter gather. These events holds its own message (MuleMessage) which may be valuable because of the payload (result). Iterating to the events allows the access to each payload for each routes taken inside scatter-gather.

10

Custom AggregatorContext ‘Original event’ is a single event that defines the actual event running before/during/after the call for scatter-gather. You may think of the Original Event as the message being processed originally.

11

Custom Aggregator

3. Iterate over the collection of events and get every data needed. If you are composing a new payload, you need to set it as payload to the OriginalEvent, and then return Original Event. If adding message properties, this should also be done in the message of the original event.

12

Custom Aggregator (Example)

top related