You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by sa_james <sa...@hotmail.com> on 2017/01/12 09:18:25 UTC

Aggregate, completion, notifybuilder

Still riding the camel and I became confused with aggregate while doing some
tests. Consider:

/from("direct:start").aggregate(constant(true)).groupExchanges().completionSize(2)
   .to("log:I-see-you")
   .to("file:target").routeId("myroute")

template.sendBody("direct:start","Exchange1")
template.sendBody("direct:start","Exchange2")
/
Now My Question:
*How do I test that the aggregated Exchange is complete?
*
I tried the followings and the first two behave differently from the last 2.
/
NotifyBuilder(context).*fromRoute("myroute")*.whenDone(1).create()
NotifyBuilder(context).*fromRoute("myroute")*.whenCompleted(1).create()

NotifyBuilder(context).*from("log:I-see-you")*.whenDone(1).create()
NotifyBuilder(context).*from("log:I-see-you")*.whenCompleted(1).create()/

*What does happen to the first 2 messages when they have been aggregated?*

THanks.

Camel is Awesome.




-----
Guile Newbie
--
View this message in context: http://camel.465427.n5.nabble.com/Aggregate-completion-notifybuilder-tp5792441.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Aggregate, completion, notifybuilder

Posted by sa_james <sa...@hotmail.com>.
Oh, I missed that.

Did I tell you how great Camel is?





-----
Guile Newbie
--
View this message in context: http://camel.465427.n5.nabble.com/Aggregate-completion-notifybuilder-tp5792441p5792514.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Aggregate, completion, notifybuilder

Posted by Claus Ibsen <cl...@gmail.com>.
use "file:target*" with * as wildcard, otherwise it matches exact.

Read the docs / book about notify builder
http://camel.apache.org/notifybuilder

It says it uses the same matching as intercept
http://camel.apache.org/intercept.html

On Fri, Jan 13, 2017 at 1:09 PM, sa_james <sa...@hotmail.com> wrote:
> Now I am getting closer to my goal.
>
> Consider this:
> route1 = from("file:target?fileName=$simple(random())")
> route2 = from("file:target")
>
> I just found out that
>  notifyBuilder.wereSentTo("file:target") does not work for the first case.
> Does it mean that the uri in nofityBuilder also take option-parameters into
> account?.
> If that is the case, then I have made a huge leap into my understanding of
> camel.
> Thanks.
>
>
>
> -----
> Guile Newbie
> --
> View this message in context: http://camel.465427.n5.nabble.com/Aggregate-completion-notifybuilder-tp5792441p5792508.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: Aggregate, completion, notifybuilder

Posted by sa_james <sa...@hotmail.com>.
Now I am getting closer to my goal.

Consider this:
route1 = from("file:target?fileName=$simple(random())")
route2 = from("file:target")

I just found out that
 notifyBuilder.wereSentTo("file:target") does not work for the first case.
Does it mean that the uri in nofityBuilder also take option-parameters into
account?.
If that is the case, then I have made a huge leap into my understanding of
camel.
Thanks.



-----
Guile Newbie
--
View this message in context: http://camel.465427.n5.nabble.com/Aggregate-completion-notifybuilder-tp5792441p5792508.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Aggregate, completion, notifybuilder

Posted by Claus Ibsen <cl...@gmail.com>.
Yes then just set notify builder to 10000 (input message) + number of
outgoing for aggregator as the size for the notifier.



On Fri, Jan 13, 2017 at 12:41 PM, sa_james <sa...@hotmail.com> wrote:
> Lets say that I am benchmarking a route.
> I send 10 000 messages to the small route from the previous example. I was
> expecting to be able to use a notifyBuilder to block until all messages are
> completed. Am I missing something?
> Thanks.
>
>
>
> -----
> Guile Newbie
> --
> View this message in context: http://camel.465427.n5.nabble.com/Aggregate-completion-notifybuilder-tp5792441p5792504.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: Aggregate, completion, notifybuilder

Posted by sa_james <sa...@hotmail.com>.
Lets say that I am benchmarking a route. 
I send 10 000 messages to the small route from the previous example. I was
expecting to be able to use a notifyBuilder to block until all messages are
completed. Am I missing something?
Thanks.



-----
Guile Newbie
--
View this message in context: http://camel.465427.n5.nabble.com/Aggregate-completion-notifybuilder-tp5792441p5792504.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Aggregate, completion, notifybuilder

Posted by Claus Ibsen <cl...@gmail.com>.
And there is also message history eip
http://camel.apache.org/message-history.html

On Fri, Jan 13, 2017 at 12:20 PM, Claus Ibsen <cl...@gmail.com> wrote:
> An exchange has a timestamp when it was created as a property you can read
>
> On Fri, Jan 13, 2017 at 11:44 AM, sa_james <sa...@hotmail.com> wrote:
>> Why does this one match?
>>
>>
>>
>>    this.context.addRoutes(new RouteBuilder() {
>>             @Override
>>             public void configure() throws Exception {
>>                 onCompletion().log("${body} completed");
>>                 from("direct:S")
>>                 .aggregate(new
>> GroupedExchangeAggregationStrategy()).constant(Boolean.TRUE).completionSize(2).completionTimeout(2000)
>>                 .split(body())
>>                 .aggregate(new
>> GroupedExchangeAggregationStrategy()).constant(Boolean.TRUE).completionSize(2).completionTimeout(2000)
>>
>>                 .to("log:icu")
>>
>>                 .to("mock:me").routeId("TEST");
>>             }
>>         });
>>         MockEndpoint mock = getMockEndpoint("mock:me");
>>         mock.expectedMessageCount(2);
>>
>>         NotifyBuilder notify = new
>> NotifyBuilder(this.context).fromRoute("TEST").whenDone(16).create();
>>         this.startCamelContext();
>>
>>         template.sendBody("direct:S", "A");
>>         template.sendBody("direct:S", "B");
>>         template.sendBody("direct:S", "C");
>>         template.sendBody("direct:S", "D");
>>
>>         boolean matches = notify.matches(20, TimeUnit.HOURS);
>>         assertTrue(matches);
>>
>> What is the best way to time how long it took for "mock:me" to receive its 2
>> messages?
>>
>>      NotifyBuilder notify = new
>> NotifyBuilder(this.context).wereSentTo("log:icu").whenCompleted(2).create();
>>      NotifyBuilder notify = new
>> NotifyBuilder(this.context).wereSentTo("mock:me").whenCompleted(2).create();
>>
>>
>>
>>
>> -----
>> Guile Newbie
>> --
>> View this message in context: http://camel.465427.n5.nabble.com/Aggregate-completion-notifybuilder-tp5792441p5792494.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: Aggregate, completion, notifybuilder

Posted by Claus Ibsen <cl...@gmail.com>.
An exchange has a timestamp when it was created as a property you can read

On Fri, Jan 13, 2017 at 11:44 AM, sa_james <sa...@hotmail.com> wrote:
> Why does this one match?
>
>
>
>    this.context.addRoutes(new RouteBuilder() {
>             @Override
>             public void configure() throws Exception {
>                 onCompletion().log("${body} completed");
>                 from("direct:S")
>                 .aggregate(new
> GroupedExchangeAggregationStrategy()).constant(Boolean.TRUE).completionSize(2).completionTimeout(2000)
>                 .split(body())
>                 .aggregate(new
> GroupedExchangeAggregationStrategy()).constant(Boolean.TRUE).completionSize(2).completionTimeout(2000)
>
>                 .to("log:icu")
>
>                 .to("mock:me").routeId("TEST");
>             }
>         });
>         MockEndpoint mock = getMockEndpoint("mock:me");
>         mock.expectedMessageCount(2);
>
>         NotifyBuilder notify = new
> NotifyBuilder(this.context).fromRoute("TEST").whenDone(16).create();
>         this.startCamelContext();
>
>         template.sendBody("direct:S", "A");
>         template.sendBody("direct:S", "B");
>         template.sendBody("direct:S", "C");
>         template.sendBody("direct:S", "D");
>
>         boolean matches = notify.matches(20, TimeUnit.HOURS);
>         assertTrue(matches);
>
> What is the best way to time how long it took for "mock:me" to receive its 2
> messages?
>
>      NotifyBuilder notify = new
> NotifyBuilder(this.context).wereSentTo("log:icu").whenCompleted(2).create();
>      NotifyBuilder notify = new
> NotifyBuilder(this.context).wereSentTo("mock:me").whenCompleted(2).create();
>
>
>
>
> -----
> Guile Newbie
> --
> View this message in context: http://camel.465427.n5.nabble.com/Aggregate-completion-notifybuilder-tp5792441p5792494.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: Aggregate, completion, notifybuilder

Posted by sa_james <sa...@hotmail.com>.
Why does this one match?


        
   this.context.addRoutes(new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                onCompletion().log("${body} completed");
                from("direct:S")
                .aggregate(new
GroupedExchangeAggregationStrategy()).constant(Boolean.TRUE).completionSize(2).completionTimeout(2000)
                .split(body())
                .aggregate(new
GroupedExchangeAggregationStrategy()).constant(Boolean.TRUE).completionSize(2).completionTimeout(2000)

                .to("log:icu")

                .to("mock:me").routeId("TEST");
            }
        });
        MockEndpoint mock = getMockEndpoint("mock:me");
        mock.expectedMessageCount(2);

        NotifyBuilder notify = new
NotifyBuilder(this.context).fromRoute("TEST").whenDone(16).create();
        this.startCamelContext();
        
        template.sendBody("direct:S", "A");
        template.sendBody("direct:S", "B");
        template.sendBody("direct:S", "C");
        template.sendBody("direct:S", "D");
        
        boolean matches = notify.matches(20, TimeUnit.HOURS);
        assertTrue(matches);

What is the best way to time how long it took for "mock:me" to receive its 2
messages?

     NotifyBuilder notify = new
NotifyBuilder(this.context).wereSentTo("log:icu").whenCompleted(2).create();
     NotifyBuilder notify = new
NotifyBuilder(this.context).wereSentTo("mock:me").whenCompleted(2).create();




-----
Guile Newbie
--
View this message in context: http://camel.465427.n5.nabble.com/Aggregate-completion-notifybuilder-tp5792441p5792494.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Aggregate, completion, notifybuilder

Posted by sa_james <sa...@hotmail.com>.
I have seen my mistakes....
It turns out, that I was declaring the notifyBuilder when the
defaultCamelContext was already started, since I was using the one from
CamelTestSupport. It was not really an aggregate problem, it was more a
NotifyBuilder problem. I had refactored the code to use the context from
camelTEstSupport and the tests were not working anymore. But I am still
digging though. I have been reading up on UOW the past day because of this
aggregate thing.
I am getting closer.
THanks.



-----
Guile Newbie
--
View this message in context: http://camel.465427.n5.nabble.com/Aggregate-completion-notifybuilder-tp5792441p5792489.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Aggregate, completion, notifybuilder

Posted by sa_james <sa...@hotmail.com>.
Okay,
I went back and read that chapter again. Still a little confused, to be
honest. It seems like every exchange in the aggregate is complete after is
has been added to the aggregate, but not the aggregate.
Lets say I would like to time how long it takes to write the two messages
into "file:target" in the previous example? I was hoping I would be able to
accomplish that with a *notifybuilder.whenComplete(1)* followed by
*notifybuilder.matches(3,hours)* until all the messages have been written.

1- How should I do it?
2- When an aggregate is created, does it have a UOW? my guess is "No" at
this point.

Thx.



-----
Guile Newbie
--
View this message in context: http://camel.465427.n5.nabble.com/Aggregate-completion-notifybuilder-tp5792441p5792481.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Aggregate, completion, notifybuilder

Posted by Claus Ibsen <cl...@gmail.com>.
If you have the Camel in Action book I suggest you read the chapter /
sections about the aggregator EIP as its one of the most complex EIPs
and its detailed explained in the book with the background information
you need to understand.

On Thu, Jan 12, 2017 at 10:18 AM, sa_james <sa...@hotmail.com> wrote:
> Still riding the camel and I became confused with aggregate while doing some
> tests. Consider:
>
> /from("direct:start").aggregate(constant(true)).groupExchanges().completionSize(2)
>    .to("log:I-see-you")
>    .to("file:target").routeId("myroute")
>
> template.sendBody("direct:start","Exchange1")
> template.sendBody("direct:start","Exchange2")
> /
> Now My Question:
> *How do I test that the aggregated Exchange is complete?
> *
> I tried the followings and the first two behave differently from the last 2.
> /
> NotifyBuilder(context).*fromRoute("myroute")*.whenDone(1).create()
> NotifyBuilder(context).*fromRoute("myroute")*.whenCompleted(1).create()
>
> NotifyBuilder(context).*from("log:I-see-you")*.whenDone(1).create()
> NotifyBuilder(context).*from("log:I-see-you")*.whenCompleted(1).create()/
>
> *What does happen to the first 2 messages when they have been aggregated?*
>
> THanks.
>
> Camel is Awesome.
>
>
>
>
> -----
> Guile Newbie
> --
> View this message in context: http://camel.465427.n5.nabble.com/Aggregate-completion-notifybuilder-tp5792441.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2