Camel AggregationStrategy keep excluded message for next aggregation iteration
<p>Hi my input file looks like this</p>

<pre><code>AAA,1
AAA,2
AAA,3
BBB,1
CCC,1
CCC,2
DDD,1
DDD,5
DDD,4
EEE,1
</code></pre>

<p>I want to split and aggregate this to multiple messages but keep associated records together like:</p>

<p>Message 1:     </p>

<pre><code>AAA,1
AAA,2
AAA,3
BBB,1
CCC,1
CCC,2
</code></pre>

<p>Message 2:  </p>

<pre><code>DDD,1
DDD,5
DDD,4
EEE,1
</code></pre>

<p>And prevent something like this:</p>

<p>Message 1:     </p>

<pre><code>AAA,1
AAA,2
AAA,3
BBB,1
CCC,1
</code></pre>

<p>Message 2:  </p>

<pre><code>CCC,2
DDD,1
DDD,5
DDD,4
EEE,1
</code></pre>

<p>CCC,2 should be written to Message 1 or CCC,1 should be written to Message 2.</p>

<p>The completionSize is not constant but should be something like a threshold. Regarding the example above working like "Aggregate 5 records in a message if there are further records beginning with CCC put them to the message too."  </p>

<p>This is my route:</p>

<pre><code>.split().tokenize("\n").streaming()
.aggregate().constant(true)
.aggregationStrategy(new MyAggregationStrategy())
.completionSize(5)
.completionTimeout(5000)
</code></pre>

<p>After reaching the completionSize threshold of 5, MyAggregationStrategy has to check the next message (newExchange) and decide if it will be aggregated to the oldExchange or not even if the size will be bigger than 5. If  the message will not be aggregated to the oldExchange, the aggregation is complete and a new aggregation begins. How do I ensure that this message that was rejected by the last aggregation will be the first message regarded in the new aggregation?</p>

<p>Since the input file may be very large I will use streaming and not read in the whole file first and then cut it to single messages by a custom bean.</p>