Versions Compared

Key

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

...

Include Page
Using This Pattern
Using This Pattern

Completing current group decided from the AggregationStrategy

Available as of Camel 2.15

The AggregationStrategy can now included a property on the returned Exchange that contains a boolean to indicate if the current group should be completed. This allows to overrule any existing completion predicates / sizes / timeouts etc, and complete the group.

For example the following logic (from an unit test) will complete the group if the message body size is larger than 5. This is done by setting the property Exchange.AGGREGATION_COMPLETE_CURRENT_GROUP to true.

Code Block
    public final class MyCompletionStrategy implements AggregationStrategy {
        @Override
        public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
            if (oldExchange == null) {
                return newExchange;
            }
            String body = oldExchange.getIn().getBody(String.class) + "+" 
                + newExchange.getIn().getBody(String.class);
            oldExchange.getIn().setBody(body);
            if (body.length() >= 5) {
                oldExchange.setProperty(Exchange.AGGREGATION_COMPLETE_CURRENT_GROUP, true);
            }
            return oldExchange;
        }
    }

 

Manually Force the Completion of All Aggregated Exchanges Immediately

...