Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The Aggregate mediator implements the Message Aggregator enterprise integration pattern and aggregates the response messages for messages that were split by the Clone or Iterate mediator and sent using the Send mediator. At the same time, it can aggregate messages in the presence of matching elements specified by the correlateOn XPath expression. The Aggregate mediator collects the incoming messages until the completion condition is satisfied. The completion condition can specify a minimum or maximum number of messages to be collected, or a timeout value in seconds, after which the aggregation terminates. Note that when the Iterate mediator is used to split the requests and produces only an n number of fragmented messages, the Aggregate mediator will terminate as soon as it receives n responses, even if you have specified a higher minimum limit.

On completion of the aggregation, the Aggregate mediator will merge all collected messages and invoke the onComplete sequence on it. The merged message will be created using the XPath expression specified by the attribute expression on the onCompleteelement.

Excerpt
hiddentrue

NOTE TO WRITERS: The following note is based on the FAQ http://docs.wso2.org/wiki/display/FAQ/Mediators#Mediators-Iterate. If you make changes to the note, be sure to make changes in the original FAQ as well.

 Note that the responses will not necessarily be aggregated in the same order that the requests were sent, even if you set the sequential attribute to true on the Iterate mediator.

...

Code Block
XML
XML
<aggregate>
   <correlateOn expression="xpath"/>?
   <completeCondition [timeout="time-in-seconds"]>
     <messageCount min="int-min" max="int-max"/>?
   </completeCondition>?
   <onComplete expression="xpath" [sequence="sequence-ref"]>
     (mediator +)?
   </onComplete>
</aggregate>

...

UI Configuration

The Aggregate Mediator field descriptions:parameters available for configuring the Aggregate mediator are as follows.

Parameter NameDescription
Aggregate ID

...

This optional attribute can be used to aggregate only responses for split messages that are created by a specific clone/iterate mediator. Aggregate ID should be the same as the ID of the corresponding clone/iterate mediator that creates split messages. This is particularly useful when aggregating responses for messages that are created using nested clone/iterate mediators.
Aggregation Expression

...

An XPath expression specifying which elements

...

should be aggregated. A set of messages that

...

are selected for aggregation is determined

...

by the value specified in the Correlation Expression field.
Completion Timeout

...

The number of seconds taken by the Aggregate mediator to wait for messages. When this time duration elapses, the aggregation will be completed. If the number of response messages reaches the number specified in the Completion Max-messages field, the aggregation will be completed even if the time duration specified for the Completion Timeout field has not elapsed.
Completion Max-messages

...

Maximum number of messages that can exist in an aggregation. When the number of response messages received reaches this number, the aggregation will be completed.
Completion Min-messages

...

Minimum number of messages required for the aggregation to complete. When the time duration entered in the Completion Timeout field is elapsed, the aggregation will be completed even if the number of minimum response messages specified has not been received. If no value is entered in the Completion Timeoutfield, the aggregation will not be completed until the number of response messages entered in the Completion Min-messages field is received.
Correlation Expression

...

 This is an XPath expression

...

which provides the basis on which response messages should be selected for aggregation. This is done by specifying a set of elements for which the messages selected should have matching values. A specific aggregation condition is set

...

via the Aggregation Expression field.

Info
titleTip

You can click

...

NameSpaces

...

to add namespaces if you are providing an expression.

...

Then the Namespace Editor panel would appear where you can provide any number of namespace prefixes and URLs used in the XPath expression. 

Enclosing Element PropertyThis parameter is used to accumulate the aggregated messages inside a single property. The name of the relevant property is entered in this field.
On Complete

The sequence to run when the aggregation is complete. You can select one of the following options:

  • Anonymous

...

  • : Select this value if you want to specify the sequence to run by adding child mediators to the Aggregate mediator instead of selecting an existing sequence. For example, if you want to send the aggregated message via the Send mediator, you can add the Send mediator as a child mediator.
  • Pick from Registry: Select this option if you want to specify a sequence which is already defined and saved in the registry. You can select the sequence from the Configuration Registry or Governance Registry. For more information,

...

Info
titleNote

You can configure the Mediator mediator using XML. Click on " switch to source view " in the "Mediator" window.

Image Modified

...

Examples

Table of Contents
maxLevel4
minLevel4

Example 1 - Sending aggregated messages through the send mediator

Code Block
XML
XML
<outSequence>
    <aggregate>
        <onComplete expression="//m0:getQuoteResponse"
                xmlns:m0="http://services.samples">
            <send/>
        </onComplete>
    </aggregate>
</outSequence>

In this example, the mediator aggregates the responses coming into the ESB, and on completion it sends the aggregated message through the Send mediator.

Example - 2 Sending aggregated messages with the enclosing element

The following example shows how to configure the Aggregate mediator to annotate the responses sent from multiple backends before forwarding them to the client.

Code Block
languagexml
<outSequence>
   <property name="info" scope="default">
      <ns:Information xmlns:ns="www.asankatechtalks.com" />
   </property>
   <aggregate id="sa">
      <completeCondition />
      <onComplete expression="$body/*[1]" enclosingElementProperty="info">
         <send />
      </onComplete>
   </aggregate>
</outSequence>

The above configuration includes the following:

ParameterDescription
<property name="info" scope="default">
      <ns:Information xmlns:ns="www.asankatechtalks.com" />
   </property>
This creates the property named info of the OM type in which all the aggregated responses are accumulated.
<aggregate id="sa">The ID of the corresponding Clone mediator that splits the messages to be aggregated by the Aggregate mediator.
<onComplete expression="$body/*[1]" enclosingElementProperty="info">This expression is used to add the info property (created earlier in this configuration) to be added to the payload of the message and for accumulating all the aggregated messages from different endpoints inside the tag created inside this property.
<send />This is the Send mediator added as a child mediator to the Aggregate mediator in order to send the aggregated and annotated messages back to the client once the aggregation is complete.

Samples

For more examples, see:

...