camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: Camel 2.15.1 Aggregator: Using multiple to() endpoints
Date Tue, 23 Jun 2015 12:46:16 GMT
Hi

A bit hard to explain without having to write endless long emails.

This is expected the aggregator uses a separate "leg" of the routing
when it sends completed outgoing messages. eg its input and output
legs are separated.


On Tue, Jun 23, 2015 at 1:11 PM, Ravi Nallappan
<ravi.nallappan@gmail.com> wrote:
> Hi,
>
> I am trying to create modular routes that at the end stitched together by a
> main route. This strategy is working for most of my other routing except
> when I use aggregator.
>
> I have created a simple test case for this scenario:
>
> <pre>
> package com.ravi.test;
>
> import org.apache.camel.Exchange;
> import org.apache.camel.builder.RouteBuilder;
> import org.apache.camel.component.mock.MockEndpoint;
> import org.apache.camel.processor.aggregate.AggregationStrategy;
> import org.apache.camel.test.junit4.CamelTestSupport;
> import org.junit.Test;
>
> public class AggregateRouteTest extends CamelTestSupport {
>   @Override
>   protected RouteBuilder createRouteBuilder() {
>     return new RouteBuilder() {
>       @Override
>       public void configure() {
>         // @formatter:off
>         from("direct://test-combine")
>           .to("direct://combine")
> //        .to("mock:result") /* 1 */
>         ;
>
>         from("direct://combine")
>           .aggregate(header("myId"), new BeanAggregationStrategy())
>             .completionSize(3)
>             .completionTimeout(3000)
>           .to("mock:result") /* 2 */
>         ;
>         // @formatter:on
>       }
>
>       class BeanAggregationStrategy implements AggregationStrategy {
>         @Override
>         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);
>           String body = oldBody + newBody;
>           oldExchange.getIn().setBody(body);
>           return oldExchange;
>         }
>       }
>     };
>   }
>
>   @Test
>   public void simpleTest() throws Exception {
>     MockEndpoint mock = getMockEndpoint("mock:result");
>     mock.expectedBodiesReceived("ABC");
>     template.sendBodyAndHeader("direct://test-combine", "A", "myId", 1);
>     template.sendBodyAndHeader("direct://test-combine", "B", "myId", 1);
>     template.sendBodyAndHeader("direct://test-combine", "C", "myId", 1); /*
> 3 */
>     assertMockEndpointsSatisfied();
>   }
> }
> </pre>
>
> This code works and test case passes. However, if I uncomment line /* 1 */ and
> comment out line /* 2 */ above, the test case fails.
>
> "direct://combine" endpoint's route contains aggregation logic, while
> "direct://test-combine"
> and "mock:result" are suppose wrapper to test the route. However, this does
> not work and requires "mock:result" to be part of "direct://combine".
>
> Even by commenting out /* 3 */ above (i.e incomplete messages to
> aggregate), we can see above code will wait awhile for a last message while
> the other modification does not even wait before failing (aggregator not
> kicked in at all?).
>
> Appreciate if anyone able to explain the reason. And if its still possible
> to keep "direct://combine" modular i.e combine endpoint's route remain free
> from before and after routes details.
>
> Thanks and regards,
> Ravi Nallappan



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Mime
View raw message