You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

Aggregator

The Aggregator from the EIP patterns allows you to combine a number of messages together into a single message.

A correlation Expression is used to determine the messages which should be aggregated together. If you want to aggregate all messages into a single message, just use a constant expression. An AggregationStrategy is used to combine the all the message exchanges for a single correlation key into a single message exchange. The default strategy just chooses the latest message; so its ideal for throttling messages.

For example imagine a stock market data system; you are receiving 30,000 messages per second; you may want to throttle down the updates as, say, a GUI cannot cope with such massive update rates. So you may want to aggregate these messages together so that within a window (defined by a maximum number of messages or a timeout), messages for the same stock are aggregated together; by just choosing the latest message and discarding the older prices. (You could apply a delta processing algorithm if you prefer to capture some of the history).

The following example shows how to aggregate messages so that only the latest message for a specific value of the cheese header are sent.

Using the Fluent Builders

Error formatting macro: snippet: java.lang.NullPointerException

If you were using JMS then you may wish to use the JMSDestination header as the correlation key; or some custom header for the stock symbol (using the above stock market example).

aggregator(header("JMSDestination"))

You can of course use many different Expression languages such as XPath, XQuery, SQL or various Scripting Languages.

For further examples of this pattern in use you could look at the junit test case

Using the Spring XML Extensions

Using This Pattern

If you would like to use this EIP Pattern then please read the Getting Started, you may also find the Architecture useful particularly the description of Endpoint and URIs. Then you could try out some of the Examples first before trying this pattern out.

  • No labels