# Aggregate-eip.md
The
[Aggregator](http://www.enterpriseintegrationpatterns.com/Aggregator.html)
from the [EIP patterns](#enterprise-integration-patterns.adoc) allows
you to combine a number of messages into a single message.
How do we combine the results of individual, but related, messages so
that they can be processed as a whole?
Use a stateful filter, an Aggregator, to collect and store individual
messages until a complete set of related messages has been received.
Then, the Aggregator publishes a single message distilled from the
individual messages.
The aggregator is one of the most complex EIP and has many features and
configurations.
The logic for combing messages together is *correlated* in buckets based
on a *correlation key*. Messages with the same correlation key are
aggregated together, using an `AggregationStrategy`.
# Aggregate options
# Exchange properties
# Worker pools
The aggregate EIP will always use a worker pool used to process all the
outgoing messages from the aggregator. The worker pool is determined
accordingly:
- If a custom `ExecutorService` has been configured, then this is used
as worker pool.
- If `parallelProcessing=true` then a *default* worker pool (is 10
worker threads by default) is created. However, the thread pool size
and other configurations can be configured using *thread pool
profiles*.
- Otherwise, a single threaded worker pool is created.
- To achieve synchronous aggregation, use an instance of
`SynchronousExecutorService` for the `executorService` option. The
aggregated output will execute in the same thread that called the
aggregator.
# Aggregating
The `AggregationStrategy` is used for aggregating the old, and the new
exchanges together into a single exchange; that becomes the next old,
when the next message is aggregated, and so forth.
Possible implementations include performing some kind of combining or
delta processing. For instance, adding line items together into an
invoice or just using the newest exchange and removing old exchanges
such as for state tracking or market data prices, where old values are
of little use.
Notice the aggregation strategy is a mandatory option and must be
provided to the aggregator.
In the aggregate method, do not create a new exchange instance to
return, instead return either the old or new exchange from the input
parameters; favor returning the old exchange whenever possible.
Here are a few example `AggregationStrategy` implementations that should
help you create your own custom strategy.
//simply combines Exchange String body values using '+' as a delimiter
class StringAggregationStrategy implements AggregationStrategy {
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
if (oldExchange == null) {
return newExchange;
}
String oldBody = oldExchange.getIn().getBody(String.class);
String newBody = newExchange.getIn().getBody(String.class);
oldExchange.getIn().setBody(oldBody + "+" + newBody);
return oldExchange;
}
}
//simply combines Exchange body values into an ArrayList