You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by bu...@apache.org on 2017/08/31 23:20:56 UTC
svn commit: r1017534 [1/5] - in /websites/production/camel/content:
aggregator.html aggregator2.html book-in-one-page.html
book-pattern-appendix.html cache/main.pageCache
Author: buildbot
Date: Thu Aug 31 23:20:55 2017
New Revision: 1017534
Log:
Production update by buildbot for camel
Modified:
websites/production/camel/content/aggregator.html
websites/production/camel/content/aggregator2.html
websites/production/camel/content/book-in-one-page.html
websites/production/camel/content/book-pattern-appendix.html
websites/production/camel/content/cache/main.pageCache
Modified: websites/production/camel/content/aggregator.html
==============================================================================
--- websites/production/camel/content/aggregator.html (original)
+++ websites/production/camel/content/aggregator.html Thu Aug 31 23:20:55 2017
@@ -86,36 +86,8 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h3 id="Aggregator-Aggregator">Aggregator</h3>
-
-<p><strong>This applies for Camel version 2.2 or older. If you use a newer version then the Aggregator has been rewritten from Camel 2.3 onwards and you should use this <a shape="rect" href="aggregator2.html">Aggregator2</a> link instead.</strong></p>
-
-<p>The <a shape="rect" class="external-link" href="http://www.enterpriseintegrationpatterns.com/Aggregator.html" rel="nofollow">Aggregator</a> from the <a shape="rect" href="enterprise-integration-patterns.html">EIP patterns</a> allows you to combine a number of messages together into a single message. </p>
-
-<p><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-external-resource" src="http://www.enterpriseintegrationpatterns.com/img/Aggregator.gif" data-image-src="http://www.enterpriseintegrationpatterns.com/img/Aggregator.gif"></span></p>
-
-<p>A correlation <a shape="rect" href="expression.html">Expression</a> 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 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. </p>
-
-<p>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).</p>
-
-<div class="confluence-information-macro confluence-information-macro-tip"><p class="title">Using the aggregator correctly</p><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body">
-<p>Torsten Mielke wrote a nice <a shape="rect" class="external-link" href="http://tmielke.blogspot.com/2009/01/using-camel-aggregator-correctly.html" rel="nofollow">blog entry</a> with his thoughts and experience on using the aggreagator. Its a well worth read.</p></div></div>
-
-<div class="confluence-information-macro confluence-information-macro-information"><p class="title">AggregationStrategy changed in Camel 2.0</p><span class="aui-icon aui-icon-small aui-iconfont-info confluence-information-macro-icon"></span><div class="confluence-information-macro-body">
-<p>In Camel 2.0 the <code>AggregationStrategy</code> callback have been changed to also be invoked on the very first Exchange.</p>
-
-<p>On the first invocation of the <code>aggregate</code> method the <code>oldExchange</code> parameter is <code>null</code>. The reason is that we have not aggregated anything yet.<br clear="none">
-So its only the <code>newExchange</code> that has a value. Usually you just return the <code>newExchange</code> in this situation. But you still have the power to decide what to do, for example you can do some alternation on the exchange or remove some headers. And a more common use case is for instance to count some values from the body payload. That could be to sum up a total amount etc.</p></div></div>
-
-<div class="confluence-information-macro confluence-information-macro-warning"><p class="title">BatchTimeout and CompletionPredicate</p><span class="aui-icon aui-icon-small aui-iconfont-error confluence-information-macro-icon"></span><div class="confluence-information-macro-body">
-<p>You cannot use both batchTimeout and completionPredicate to trigger a completion based on either on reaching its goal first. The batch timeout will always trigger first, at that given interval.</p></div></div>
-
-<p><strong>Using the <a shape="rect" href="fluent-builders.html">Fluent Builders</a></strong></p>
-
-<p>The following example shows how to aggregate messages so that only the latest message for a specific value of the <strong>cheese</strong> header are sent.</p>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
+<div class="wiki-content maincontent"><h3 id="Aggregator-Aggregator">Aggregator</h3><p><strong>This applies for Camel version 2.2 or older. If you use a newer version then the Aggregator has been rewritten from Camel 2.3 on and you should use this <a shape="rect" href="aggregator2.html">Aggregator2</a> link instead.</strong></p><p>The <a shape="rect" class="external-link" href="http://www.enterpriseintegrationpatterns.com/Aggregator.html" rel="nofollow">Aggregator</a> from the <a shape="rect" href="enterprise-integration-patterns.html">EIP patterns</a> allows you to combine a number of messages together into a single message.</p><p><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-external-resource" src="http://www.enterpriseintegrationpatterns.com/img/Aggregator.gif" data-image-src="http://www.enterpriseintegrationpatterns.com/img/Aggregator.gif"></span></p><p>A correlation <a shape="rect" href="expression.html">Expression</a> is used t
o 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 <strong><code>AggregationStrategy</code></strong> is used to combine 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.</p><p>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).</p><div class="confluence-informatio
n-macro confluence-information-macro-tip"><p class="title">Using the aggregator correctly</p><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>Torsten Mielke wrote a nice <a shape="rect" class="external-link" href="http://tmielke.blogspot.com/2009/01/using-camel-aggregator-correctly.html" rel="nofollow">blog entry</a> with his thoughts and experience on using the aggreagator. Its a well worth read.</p></div></div><div class="confluence-information-macro confluence-information-macro-information"><p class="title">AggregationStrategy changed in Camel 2.0</p><span class="aui-icon aui-icon-small aui-iconfont-info confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>In Camel 2.0 the <strong><code>AggregationStrategy</code></strong> callback have been changed to also be invoked on the very first Exchange.</p><p>On the first invocation of the <strong><co
de>aggregate</code></strong> method the <strong><code>oldExchange</code></strong> parameter is <strong><code>null</code></strong>. The reason is that we have not aggregated anything yet.<br clear="none"> So its only the <strong><code>newExchange</code></strong> that has a value. Usually you just return the <strong><code>newExchange</code></strong> in this situation. But you still have the power to decide what to do, for example you can do some alternation on the exchange or remove some headers. And a more common use case is for instance to count some values from the body payload. That could be to sum up a total amount etc.</p></div></div><div class="confluence-information-macro confluence-information-macro-warning"><p class="title">BatchTimeout and CompletionPredicate</p><span class="aui-icon aui-icon-small aui-iconfont-error confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>You cannot use both <strong><code>batchTimeout</code></strong>
and <strong><code>completionPredicate</code></strong> to trigger a completion based on either on reaching its goal first. The batch timeout will always trigger first, at that given interval.</p></div></div><p><strong>Using the <a shape="rect" href="fluent-builders.html">Fluent Builders</a></strong></p><p>The following example shows how to aggregate messages so that only the latest message for a specific value of the <strong><code>cheese</code></strong> header are sent.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[
// in this route we aggregate all from direct:state based on the header id cheese
from("direct:start").aggregate(header("cheese")).to("mock:result");
@@ -131,21 +103,13 @@ from("direct:predicate").aggre
from("direct:outBatchPredicate").aggregate(header("cheese"), new MyAggregationStrategy()).
completionPredicate(header("aggregated").isEqualTo(5)).outBatchSize(10).to("mock:result");
]]></script>
-</div></div>
-
-<p>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).</p>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
-from("activemq:someReallyFastTopic").aggregator(header("JMSDestination")).to("activemq:someSlowTopicForGuis");
+</div></div>If you were using JMS then you may wish to use the <strong><code>JMSDestination</code></strong> header as the correlation key; or some custom header for the stock symbol (using the above stock market example).<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[from("activemq:someReallyFastTopic")
+ .aggregator(header("JMSDestination"))
+ .to("activemq:someSlowTopicForGuis");
]]></script>
-</div></div>
-
-<p>You can of course use many different <a shape="rect" href="expression.html">Expression</a> languages such as <a shape="rect" href="xpath.html">XPath</a>, <a shape="rect" href="xquery.html">XQuery</a>, <a shape="rect" href="sql.html">SQL</a> or various <a shape="rect" href="scripting-languages.html">Scripting Languages</a>. <br clear="none">
-Here is an example using <strong>XPath</strong>:</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
-//aggregate based on the message content using an XPath expression
+</div></div><p>You can of course use many different <a shape="rect" href="expression.html">Expression</a> languages such as <a shape="rect" href="xpath.html">XPath</a>, <a shape="rect" href="xquery.html">XQuery</a>, <a shape="rect" href="sql.html">SQL</a> or various <a shape="rect" href="scripting-languages.html">Scripting Languages</a>. <br clear="none"> Here is an example using <strong>XPath</strong>:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[//aggregate based on the message content using an XPath expression
//example assumes an XML document starting with <stockQuote symbol='...'>
//aggregate messages based on their symbol attribute within the <stockQuote> element
from("seda:start").aggregate().xpath("/stockQuote/@symbol", String.class).batchSize(5).to("mock:result");
@@ -154,28 +118,14 @@ from("seda:start").aggregate()
//one exchange and all the other messages (different symbol or different root element) into another exchange.
from("seda:start").aggregate().xpath("name(/stockQuote[@symbol='APACHE'])", String.class).batchSize(5).to("mock:result");
]]></script>
-</div></div>
-
-<p>For further examples of this pattern in use you could look at the <a shape="rect" class="external-link" href="http://svn.apache.org/viewvc/camel/tags/camel-2.2.0/camel-core/src/test/java/org/apache/camel/processor/AggregatorTest.java?view=markup">junit test case</a></p>
-
-<p><strong>Using the <a shape="rect" href="spring-xml-extensions.html">Spring XML Extensions</a></strong></p>
-
-<div class="confluence-information-macro confluence-information-macro-information"><span class="aui-icon aui-icon-small aui-iconfont-info confluence-information-macro-icon"></span><div class="confluence-information-macro-body">
-<p>The correlationExpression element is in Camel 2.0. For earliler versions of Camel you will need to specify your expression without the enclosing correlationExpression element.</p>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
-<aggregator>
+</div></div><p>For further examples of this pattern in use you could look at the <a shape="rect" class="external-link" href="http://svn.apache.org/viewvc/camel/tags/camel-2.2.0/camel-core/src/test/java/org/apache/camel/processor/AggregatorTest.java?view=markup">junit test case</a></p><p><strong>Using the <a shape="rect" href="spring-xml-extensions.html">Spring XML Extensions</a></strong></p><div class="confluence-information-macro confluence-information-macro-information"><span class="aui-icon aui-icon-small aui-iconfont-info confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>The <strong><code>correlationExpression</code></strong> element is in Camel 2.0. For earlier versions of Camel you will need to specify your expression without the enclosing <strong><code>correlationExpression</code></strong> element.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[<aggregator>
<simple>header.cheese</simple>
<to uri="mock:result"/>
</aggregator>
]]></script>
-</div></div> </div></div>
-
-<p>The following example shows how to create a simple aggregator using the XML notation; using an <a shape="rect" href="expression.html">Expression</a> for the correlation value used to aggregate messages together.</p>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
+</div></div></div></div><p>The following example shows how to create a simple aggregator using the XML notation; using an <a shape="rect" href="expression.html">Expression</a> for the correlation value used to aggregate messages together.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: xml; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start"/>
@@ -246,12 +196,8 @@ from("seda:start").aggregate()
</route>
</camelContext>
]]></script>
-</div></div>
-
-<p>You can specify your own AggregationStrategy if you prefer as shown in the following example</p>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
+</div></div>You can specify your own <strong><code>AggregationStrategy</code></strong> if you prefer as shown in the following example<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: xml; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start"/>
@@ -266,36 +212,8 @@ from("seda:start").aggregate()
<bean id="aggregatorStrategy" class="org.apache.camel.spring.processor.MyAggregator"/>
]]></script>
-</div></div>
-
-<p>Notice how the <strong>strategyRef</strong> attribute is used on the <strong><aggregator></strong> element to refer to the custom strategy in Spring.</p>
-
-<h3 id="Aggregator-ExchangeProperties">Exchange Properties</h3>
-<p>The following properties is set on each Exchange that are aggregated:</p>
-<div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> header </p></th><th colspan="1" rowspan="1" class="confluenceTh"><p> type </p></th><th colspan="1" rowspan="1" class="confluenceTh"><p> description </p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <code>org.apache.camel.Exchange.AggregatedCount</code> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> int </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Camel 1.x: The total number of Exchanges aggregated in this combined Exchange. </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <code>CamelAggregatedSize</code> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> int </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Camel 2.0: The total number of Exchanges aggregated into this combined Exchange. </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> <code>CamelAg
gregatedIndex</code> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> int </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Camel 2.0: The current index of this Exchange in the batch. </p></td></tr></tbody></table></div>
-
-
-<h3 id="Aggregator-Batchoptions">Batch options</h3>
-<p>The aggregator supports the following batch options:</p>
-<div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p> Option </p></th><th colspan="1" rowspan="1" class="confluenceTh"><p> Default </p></th><th colspan="1" rowspan="1" class="confluenceTh"><p> Description </p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> batchSize </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> 100 </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> The <strong>in</strong> batch size. This is the number of incoming exchanges that is processed by the aggregator and when this threshold is reached the batch is completed and send. <strong>Camel 1.6.2/2.0:</strong> You can disable the batch size so the Aggregator is only triggered by timeout by setting the <code>batchSize</code> to 0 (or negative). In <strong>Camel 1.6.1</strong> or older you can set the <code>batchSize</code> to a very large number to archive the same. </p></td></tr><tr><td colspan="1" rowspan="
1" class="confluenceTd"><p> outBatchSize </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> 0 </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> <strong>Camel 1.5:</strong> The <strong>out</strong> batch size. This is the number of exchanges currently aggregated in the <code>AggregationCollection</code>. When this threshold is reached the batch is completed and send. By default this option is disabled. The difference to the <code>batchSize</code> options is that this is for outgoing, so setting this size to e.g. 50 ensures that this batch will at maximum contain 50 exchanges when its sent. </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> batchTimeout </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> 1000L </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Timeout in millis. How long should the aggregator wait before its completed and sends whatever it has currently aggregated. </p></td></tr><tr><td colspan="1" rowspa
n="1" class="confluenceTd"><p> groupExchanges </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> false </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> <strong>Camel 2.0</strong>: If enabled then Camel will group all aggregated Exchanges into a single combined <code>org.apache.camel.impl.GroupedExchange</code> holder class that holds all the aggregated Exchanges. And as a result only one Exchange is being sent out from the aggregator. Can be used to combine many incomming Exchanges into a single output Exchange without coding a custom AggregationStrategy yourself. </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> batchConsumer </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> false </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> <strong>Camel 2.0</strong>: This option is if the exchanges is coming from a <a shape="rect" href="batch-consumer.html">Batch Consumer</a>. Then when enabled the <a shape="rect" href="agg
regator.html">Aggregator</a> will use the batch size determined by the <a shape="rect" href="batch-consumer.html">Batch Consumer</a> in the message header <code>CamelBatchSize</code>. See more details at <a shape="rect" href="batch-consumer.html">Batch Consumer</a>. This can be used to aggregate all files consumed from a <a shape="rect" href="file2.html">File</a> endpoint in that given poll. </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p> completionPredicate </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> null </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> Allows you to use a <a shape="rect" href="predicate.html">Predicate</a> to signal when an aggregation is complete. See <strong>warning</strong> in top of this page. </p></td></tr></tbody></table></div>
-
-
-<h3 id="Aggregator-AggregationCollectionandAggregationStrategy">AggregationCollection and AggregationStrategy</h3>
-
-<p>This aggregator uses a AggregationCollection to store the exchanges that is currently aggregated. The AggregationCollection uses a correlation <a shape="rect" href="expression.html">Expression</a> and an AggregationStrategy.</p>
-<ul class="alternate"><li>The correlation <a shape="rect" href="expression.html">Expression</a> is used to correlate the incoming exchanges. The default implementation will group messages based on the correlation expression. Other implementations could for instance just add all exchanges as a batch.</li><li>The strategy is used for aggregate the old (lookup by its correlation id) and the new exchanges together into a single exchange. Possible implementations include performing some kind of combining or delta processing, such as 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.</li></ul>
-
-
-<p>Camel provides these implementations:</p>
-<ul class="alternate"><li>DefaultAggregationCollection</li><li>PredicateAggregationCollection</li><li>UseLatestAggregationStrategy</li></ul>
-
-
-<h3 id="Aggregator-Examples">Examples</h3>
-
-<h4 id="Aggregator-Defaultexample">Default example</h4>
-<p>By default Camel uses <code>DefaultAggregationCollection</code> and <code>UseLatestAggregationStrategy</code>, so this simple example will just keep the latest received exchange for the given correlation <a shape="rect" href="expression.html">Expression</a>:</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
+</div></div>Notice how the <strong><code>strategyRef</code></strong> attribute is used on the <strong><code><aggregator></code></strong> element to refer to the custom strategy in Spring.<h3 id="Aggregator-ExchangeProperties">Exchange Properties</h3><p>The following properties is set on each Exchange that are aggregated:</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>header</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>type</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>description</p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>org.apache.camel.Exchange.AggregatedCount</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>int</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Camel 1.x: The total number of Exchanges aggregated in this combined Exchange.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">
<p><code>CamelAggregatedSize</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>int</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Camel 2.0: The total number of Exchanges aggregated into this combined Exchange.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>CamelAggregatedIndex</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>int</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Camel 2.0: The current index of this Exchange in the batch.</p></td></tr></tbody></table></div><h3 id="Aggregator-Batchoptions">Batch options</h3><p>The aggregator supports the following batch options:</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Option</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Default</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1" rowspan="1" class="conflue
nceTd"><p><code>batchSize</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>100</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The <strong>in</strong> batch size. This is the number of incoming exchanges that is processed by the aggregator and when this threshold is reached the batch is completed and send. </p><p><strong>Camel 1.6.2/2.0:</strong> You can disable the batch size so the Aggregator is only triggered by timeout by setting the <strong><code>batchSize</code></strong> to 0 (or negative).</p><p>In <strong>Camel 1.6.1</strong> or older you can set the <strong><code>batchSize</code></strong> to a very large number to archive the same.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>outBatchSize</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>0</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 1.5:</strong> The <strong>out</strong> batch size. This is th
e number of exchanges currently aggregated in the <strong><code>AggregationCollection</code></strong>. When this threshold is reached the batch is completed and send. By default this option is disabled. The difference to the <strong><code>batchSize</code></strong> options is that this is for outgoing, so setting this size to e.g. 50 ensures that this batch will at maximum contain 50 exchanges when its sent.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>batchTimeout</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>1000L</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Timeout in millis. How long should the aggregator wait before its completed and sends whatever it has currently aggregated.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>groupExchanges</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1" rowspan="1" class="confluenc
eTd"><p><strong>Camel 2.0</strong>: If enabled then Camel will group all aggregated Exchanges into a single combined <strong><code>org.apache.camel.impl.GroupedExchange</code></strong> holder class that holds all the aggregated Exchanges. And as a result only one Exchange is being sent out from the aggregator. Can be used to combine many incoming Exchanges into a single output Exchange without coding a custom <strong><code>AggregationStrategy</code></strong> yourself.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>batchConsumer</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.0</strong>: This option is if the exchanges is coming from a <a shape="rect" href="batch-consumer.html">Batch Consumer</a>. Then when enabled the <a shape="rect" href="aggregator.html">Aggregator</a> will use the batch size determined by the <a shape="rect" href="batc
h-consumer.html">Batch Consumer</a> in the message header <strong><code>CamelBatchSize</code></strong>. See more details at <a shape="rect" href="batch-consumer.html">Batch Consumer</a>. This can be used to aggregate all files consumed from a <a shape="rect" href="file2.html">File</a> endpoint in that given poll.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>completionPredicate</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Allows you to use a <a shape="rect" href="predicate.html">Predicate</a> to signal when an aggregation is complete. See <strong>warning</strong> in top of this page.</p></td></tr></tbody></table></div><h3 id="Aggregator-AggregationCollectionandAggregationStrategy"><code>AggregationCollection</code> and <code>AggregationStrategy</code></h3><p>This aggregator uses a <strong><code>AggregationCollection</code></strong> to store the e
xchanges that is currently aggregated. The <strong><code>AggregationCollection</code></strong> uses a correlation <a shape="rect" href="expression.html">Expression</a> and an <strong><code>AggregationStrategy</code></strong>.</p><ul class="alternate"><li>The correlation <a shape="rect" href="expression.html">Expression</a> is used to correlate the incoming exchanges. The default implementation will group messages based on the correlation expression. Other implementations could for instance just add all exchanges as a batch.</li><li>The strategy is used for aggregate the old (lookup by its correlation id) and the new exchanges together into a single exchange. Possible implementations include performing some kind of combining or delta processing, such as 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.</li></ul><p>Camel provides these implem
entations:</p><ul class="alternate"><li><strong><code>DefaultAggregationCollection</code></strong></li><li><strong><code>PredicateAggregationCollection</code></strong></li><li><strong><code>UseLatestAggregationStrategy</code></strong></li></ul><h3 id="Aggregator-Examples">Examples</h3><h4 id="Aggregator-Defaultexample">Default example</h4><p>By default Camel uses <strong><code>DefaultAggregationCollection</code></strong> and <strong><code>UseLatestAggregationStrategy</code></strong>, so this simple example will just keep the latest received exchange for the given correlation <a shape="rect" href="expression.html">Expression</a>:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[
// our route is aggregating from the direct queue and sending the response to the mock
from("direct:start")
// aggregated by header id
@@ -306,12 +224,8 @@ from("direct:start")
.batchTimeout(500L)
.to("mock:result");
]]></script>
-</div></div>
-
-<h4 id="Aggregator-UsingPredicateAggregationCollection">Using PredicateAggregationCollection</h4>
-<p>The PredicateAggregationCollection is an extension to DefaultAggregationCollection that uses a <a shape="rect" href="predicate.html">Predicate</a> as well to determine the completion. For instance the <a shape="rect" href="predicate.html">Predicate</a> can test for a special header value, a number of maximum aggregated so far etc. To use this the routing is a bit more complex as we need to create our AggregationCollection object as follows:</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
+</div></div><h4 id="Aggregator-UsingPredicateAggregationCollection">Using <code>PredicateAggregationCollection</code></h4><p>The <strong><code>PredicateAggregationCollection</code></strong> is an extension to <strong><code>DefaultAggregationCollection</code></strong> that uses a <a shape="rect" href="predicate.html">Predicate</a> as well to determine the completion. For instance the <a shape="rect" href="predicate.html">Predicate</a> can test for a special header value, a number of maximum aggregated so far etc. To use this the routing is a bit more complex as we need to create our <strong><code>AggregationCollection</code></strong> object as follows:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[
// create the aggregation collection we will use.
// - we will correlate the received message based on the id header
// - as we will just keep the latest message we use the latest strategy
@@ -328,19 +242,11 @@ from("direct:start")
.batchTimeout(500L)
.to("mock:result");
]]></script>
-</div></div>
-<p>In this sample we use the predicate that we want at most 3 exchanges aggregated by the same correlation id, this is defined as:</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
-header(Exchange.AGGREGATED_COUNT).isEqualTo(3)
-]]></script>
-</div></div>
-<p>Using this the aggregator will complete if we receive 3 exchanges with the same correlation id or when the specified timeout of 500 msecs has elapsed (whichever criteria is met first).</p>
-
-<h4 id="Aggregator-Usingcustomaggregationstrategy">Using custom aggregation strategy</h4>
-<p>In this example we will aggregate incoming bids and want to aggregate the highest bid. So we provide our own strategy where we implement the code logic:</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
+</div></div>In this sample we use the predicate that we want at most 3 exchanges aggregated by the same correlation id, this is defined as:<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[header(Exchange.AGGREGATED_COUNT).isEqualTo(3)
+]]></script>
+</div></div><p>Using this the aggregator will complete if we receive 3 exchanges with the same correlation id or when the specified timeout of 500 msecs has elapsed (whichever criteria is met first).</p><h4 id="Aggregator-UsingCustomAggregationStrategy">Using Custom Aggregation Strategy</h4><p>In this example we will aggregate incoming bids and want to aggregate the highest bid. So we provide our own strategy where we implement the code logic:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[
private static class MyAggregationStrategy implements AggregationStrategy {
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
@@ -355,11 +261,8 @@ private static class MyAggregationStrate
}
}
]]></script>
-</div></div>
-
-<p>Then we setup the routing as follows:</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
+</div></div>Then we setup the routing as follows:<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[
// our route is aggregating from the direct queue and sending the response to the mock
from("direct:start")
// aggregated by header id and use our own strategy how to aggregate
@@ -368,11 +271,8 @@ from("direct:start")
.batchTimeout(500L)
.to("mock:result");
]]></script>
-</div></div>
-
-<p>And since this is based on an unit test we show the test code that send the bids and what is expected as the <strong>winners</strong>:</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
+</div></div>And since this is based on an unit test we show the test code that send the bids and what is expected as the <strong><code>winners</code></strong>:<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[
MockEndpoint result = getMockEndpoint("mock:result");
// we expect to find the two winners with the highest bid
@@ -388,12 +288,8 @@ template.sendBodyAndHeader("direct:
assertMockEndpointsSatisfied();
]]></script>
-</div></div>
-
-<h4 id="Aggregator-Usingcustomaggregationcollection">Using custom aggregation collection</h4>
-<p>In this example we will aggregate incoming bids and want to aggregate the bids in reverse order (this is just an example). So we provide our own collection where we implement the code logic:</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
+</div></div><h4 id="Aggregator-UsingCustomAggregationCollection">Using Custom Aggregation Collection</h4><p>In this example we will aggregate incoming bids and want to aggregate the bids in reverse order (this is just an example). So we provide our own collection where we implement the code logic:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[
class MyReverseAggregationCollection extends AbstractCollection<Exchange> implements AggregationCollection {
private List<Exchange> collection = new ArrayList<Exchange>();
@@ -440,11 +336,8 @@ class MyReverseAggregationCollection ext
}
}
]]></script>
-</div></div>
-
-<p>Then we setup the routing as follows:</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
+</div></div>Then we setup the routing as follows:<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[
// our route is aggregating from the direct queue and sending the response to the mock
from("direct:start")
// use our own collection for aggregation
@@ -453,11 +346,8 @@ from("direct:start")
.batchTimeout(500L)
.to("mock:result");
]]></script>
-</div></div>
-
-<p>And since this is based on an unit test we show the test code that send the bids and what is expected as the expected reverse order:</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
+</div></div>And since this is based on an unit test we show the test code that send the bids and what is expected as the expected reverse order:<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[
MockEndpoint result = getMockEndpoint("mock:result");
// we expect 5 messages since our custom aggregation collection just gets it all
@@ -474,14 +364,8 @@ template.sendBodyAndHeader("direct:
assertMockEndpointsSatisfied();
]]></script>
-</div></div>
-
-<h5 id="Aggregator-CustomaggregationcollectioninSpringDSL">Custom aggregation collection in Spring DSL</h5>
-
-<p>You can also specify a custom aggregation collection in the Spring DSL. Here is an example for Camel 2.0</p>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
+</div></div><h5 id="Aggregator-CustomaggregationcollectioninSpringDSL">Custom aggregation collection in Spring DSL</h5><p>You can also specify a custom aggregation collection in the Spring DSL. Here is an example for Camel 2.0</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: xml; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start"/>
@@ -493,25 +377,14 @@ assertMockEndpointsSatisfied();
<bean id="aggregatorCollection" class="org.apache.camel.processor.aggregator.MyReverseAggregationCollection"/>
]]></script>
-</div></div>
-
-<p>In Camel 1.5.1 you will need to specify the aggregator as</p>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
-<aggregator batchTimeout="500" collectionRef="aggregatorCollection">
+</div></div>In Camel 1.5.1 you will need to specify the aggregator as:<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[<aggregator batchTimeout="500" collectionRef="aggregatorCollection">
<expression/>
<to uri="mock:result"/>
</aggregator>
]]></script>
-</div></div>
-
-<h4 id="Aggregator-UsingGroupedExchanges">Using Grouped Exchanges</h4>
-<p><strong>Available as of Camel 2.0</strong></p>
-
-<p>You can enable grouped exchanges to combine all aggregated exchanges into a single <code>org.apache.camel.impl.GroupedExchange</code> holder class that contains all the individual aggregated exchanges. This allows you to process a single Exchange containing all the aggregated exchange. Lets start with how to configure this in the router:</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
+</div></div><h4 id="Aggregator-UsingGroupedExchanges">Using Grouped Exchanges</h4><p><strong>Available as of Camel 2.0</strong></p><p>You can enable grouped exchanges to combine all aggregated exchanges into a single <strong><code>org.apache.camel.impl.GroupedExchange</code></strong> holder class that contains all the individual aggregated exchanges. This allows you to process a single Exchange containing all the aggregated exchange. Lets start with how to configure this in the router:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[
// our route is aggregating from the direct queue and sending the response to the mock
from("direct:start")
// aggregate all using same expression
@@ -522,12 +395,8 @@ from("direct:start")
.groupExchanges()
.to("mock:result");
]]></script>
-</div></div>
-
-<p>And the next part is part of an unit code that demonstrates this feature as we send in 5 exchanges each with a different value in the body.<br clear="none">
-And we will only get 1 exchange out of the aggregator, but we can access all the individual aggregated exchanges from the List which we can extract as a property from the Exchange using the key <code>Exchange.GROUPED_EXCHANGE</code>.</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
+</div></div>And the next part is part of an unit code that demonstrates this feature as we send in 5 exchanges each with a different value in the body. And we will only get 1 exchange out of the aggregator, but we can access all the individual aggregated exchanges from the List which we can extract as a property from the Exchange using the key <strong><code>Exchange.GROUPED_EXCHANGE</code></strong>.<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[
MockEndpoint result = getMockEndpoint("mock:result");
// we expect 1 messages since we group all we get in using the same correlation key
@@ -553,30 +422,13 @@ assertEquals("130", grouped.ge
assertEquals("200", grouped.get(3).getIn().getBody(String.class));
assertEquals("190", grouped.get(4).getIn().getBody(String.class));
]]></script>
-</div></div>
-
-<h4 id="Aggregator-UsingBatchConsumer">Using Batch Consumer</h4>
-<p><strong>Available as of Camel 2.0</strong></p>
-
-<p>The <a shape="rect" href="aggregator.html">Aggregator</a> can work together with the <a shape="rect" href="batch-consumer.html">Batch Consumer</a> to aggregate the total number of messages that the <a shape="rect" href="batch-consumer.html">Batch Consumer</a> have reported. This allows you for instance to aggregate all files polled using the <a shape="rect" href="file2.html">File</a> consumer.</p>
-
-<p>For example:</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
-from("file://inbox")
+</div></div><h4 id="Aggregator-UsingBatchConsumer">Using Batch Consumer</h4><p><strong>Available as of Camel 2.0</strong></p><p>The <a shape="rect" href="aggregator.html">Aggregator</a> can work together with the <a shape="rect" href="batch-consumer.html">Batch Consumer</a> to aggregate the total number of messages that the <a shape="rect" href="batch-consumer.html">Batch Consumer</a> have reported. This allows you for instance to aggregate all files polled using the <a shape="rect" href="file2.html">File</a> consumer.</p><p>For example:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: bash; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[from("file://inbox")
.aggregate(xpath("//order/@customerId"), new AggregateCustomerOrderStrategy()).batchConsumer().batchTimeout(60000).to("bean:processOrder");
]]></script>
-</div></div>
-
-<p>When using <code>batchConsumer</code> Camel will automatic adjust the batchSize according to reported by the <a shape="rect" href="batch-consumer.html">Batch Consumer</a> in this case the file consumer.<br clear="none">
-So if we poll in 7 files then the aggregator will aggregate all 7 files before it completes. As the timeout is still in play we set it to 60 seconds.</p>
-
-<h4 id="Aggregator-UsingThisPattern">Using This Pattern</h4>
-
-<p>If you would like to use this EIP Pattern then please read the <a shape="rect" href="getting-started.html">Getting Started</a>, you may also find the <a shape="rect" href="architecture.html">Architecture</a> useful particularly the description of <a shape="rect" href="endpoint.html">Endpoint</a> and <a shape="rect" href="uris.html">URIs</a>. Then you could try out some of the <a shape="rect" href="examples.html">Examples</a> first before trying this pattern out.</p>
+</div></div><p>When using <strong><code>batchConsumer</code></strong> Camel will automatic adjust the <strong><code>batchSize</code></strong> according to reported by the <a shape="rect" href="batch-consumer.html">Batch Consumer</a> in this case the file consumer. So if we poll in 7 files then the aggregator will aggregate all 7 files before it completes. As the timeout is still in play we set it to 60 seconds.</p><p></p><h4 id="Aggregator-UsingThisPattern">Using This Pattern</h4>
-<h3 id="Aggregator-Seealso">See also</h3>
-<ul class="alternate"><li>The <a shape="rect" href="loan-broker-example.html">Loan Broker Example</a> which uses an aggregator</li><li><a shape="rect" class="external-link" href="http://tmielke.blogspot.com/2009/01/using-camel-aggregator-correctly.html" rel="nofollow">Blog post by Torsten Mielke</a> about using the aggregator correctly.</li></ul></div>
+<p>If you would like to use this EIP Pattern then please read the <a shape="rect" href="getting-started.html">Getting Started</a>, you may also find the <a shape="rect" href="architecture.html">Architecture</a> useful particularly the description of <a shape="rect" href="endpoint.html">Endpoint</a> and <a shape="rect" href="uris.html">URIs</a>. Then you could try out some of the <a shape="rect" href="examples.html">Examples</a> first before trying this pattern out.</p><h3 id="Aggregator-Seealso">See also</h3><ul class="alternate"><li>The <a shape="rect" href="loan-broker-example.html">Loan Broker Example</a> which uses an aggregator</li><li><a shape="rect" class="external-link" href="http://tmielke.blogspot.com/2009/01/using-camel-aggregator-correctly.html" rel="nofollow">Blog post by Torsten Mielke</a> about using the aggregator correctly.</li></ul></div>
</td>
<td valign="top">
<div class="navigation">