You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Keith Freeman <8f...@gmail.com> on 2013/10/11 21:58:43 UTC
Java DSL: do I have to have a child for a split()?
My route is built in parts from different spots in my code, and at one
point I do a split:
choice().when(...).bean(...).split().method(splitBean,
"splitMethod").endChoice().otherwise().bean(...);
This results in a "IllegalArgumentException: Definition has no children
on Split...".
But at this point in the code I don't know what's going to be added to
the route, I just want the results of the split() to be forwarded down
the route. I currently accomplish this by sticking a no-op processor
into the route:
...split().method(...).process(new Processor() { public void
process(Exchange e) { /* no-op */ }}).endChoice()...
Which works fine, but do I really have to do this (it seems kind of ugly
and inefficient)? Is there something better as a Camel coding idiom
that's maybe more efficient?
Re: Java DSL: do I have to have a child for a split()?
Posted by Keith Freeman <8f...@gmail.com>.
To your question: I guess it's just a matter of the camel DSL semantics:
the output of the split() is multiple bodies that will be handled later
in the route, not here within the context of the choice(), so it seems
awkward to have to add a processor that does exactly nothing.
To your suggestion: I agree that's not as ugly, and is probably what
I'll do. Also handy if I have any other split()'s like this in my route.
I'll find out soon in testing, but does a no-op processor add any
significant performance overhead (i.e. beyond a couple of extra function
calls)? If so I may have to try to twist my design around to avoid it.
On 10/12/2013 07:31 AM, Christian Müller wrote:
> Your route is the following (I formatted it a bit):
> choice()
> .when(...).bean(...)
> .split().method(splitBean, "splitMethod")
> .endChoice()
> .otherwise()
> .bean(...);
>
> When your write "I just want the results of the split() to be forwarded
> down the route", how do you do this without a processor/bean/endpoint in
> your route between the split and endChoice?
>
> And by the way, instead of
> .process(new Processor() { public void process(Exchange e) { /* no-op */ }})
>
> you could use
> to("bean:MyNoopProcessor")
>
> and provide a MyNoopProcessor as regular class. It's a bit less ugly IMO.
> ;-)
>
> Best,
>
> Christian
> -----------------
>
> Software Integration Specialist
>
> Apache Member
> V.P. Apache Camel | Apache Camel PMC Member | Apache Camel committer
> Apache Incubator PMC Member
>
> https://www.linkedin.com/pub/christian-mueller/11/551/642
>
>
> On Fri, Oct 11, 2013 at 9:58 PM, Keith Freeman <8f...@gmail.com> wrote:
>
>> My route is built in parts from different spots in my code, and at one
>> point I do a split:
>>
>> choice().when(...).bean(...).**split().method(splitBean,
>> "splitMethod").endChoice().**otherwise().bean(...);
>>
>> This results in a "IllegalArgumentException: Definition has no children on
>> Split...".
>>
>> But at this point in the code I don't know what's going to be added to the
>> route, I just want the results of the split() to be forwarded down the
>> route. I currently accomplish this by sticking a no-op processor into the
>> route:
>>
>> ...split().method(...).**process(new Processor() { public void
>> process(Exchange e) { /* no-op */ }}).endChoice()...
>>
>> Which works fine, but do I really have to do this (it seems kind of ugly
>> and inefficient)? Is there something better as a Camel coding idiom that's
>> maybe more efficient?
>>
Re: Java DSL: do I have to have a child for a split()?
Posted by Christian Müller <ch...@gmail.com>.
Your route is the following (I formatted it a bit):
choice()
.when(...).bean(...)
.split().method(splitBean, "splitMethod")
.endChoice()
.otherwise()
.bean(...);
When your write "I just want the results of the split() to be forwarded
down the route", how do you do this without a processor/bean/endpoint in
your route between the split and endChoice?
And by the way, instead of
.process(new Processor() { public void process(Exchange e) { /* no-op */ }})
you could use
to("bean:MyNoopProcessor")
and provide a MyNoopProcessor as regular class. It's a bit less ugly IMO.
;-)
Best,
Christian
-----------------
Software Integration Specialist
Apache Member
V.P. Apache Camel | Apache Camel PMC Member | Apache Camel committer
Apache Incubator PMC Member
https://www.linkedin.com/pub/christian-mueller/11/551/642
On Fri, Oct 11, 2013 at 9:58 PM, Keith Freeman <8f...@gmail.com> wrote:
> My route is built in parts from different spots in my code, and at one
> point I do a split:
>
> choice().when(...).bean(...).**split().method(splitBean,
> "splitMethod").endChoice().**otherwise().bean(...);
>
> This results in a "IllegalArgumentException: Definition has no children on
> Split...".
>
> But at this point in the code I don't know what's going to be added to the
> route, I just want the results of the split() to be forwarded down the
> route. I currently accomplish this by sticking a no-op processor into the
> route:
>
> ...split().method(...).**process(new Processor() { public void
> process(Exchange e) { /* no-op */ }}).endChoice()...
>
> Which works fine, but do I really have to do this (it seems kind of ugly
> and inefficient)? Is there something better as a Camel coding idiom that's
> maybe more efficient?
>
Re: Java DSL: do I have to have a child for a split()?
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
Yes a child output is expected.
Maybe instead of using splitter use message translator, and return
what your want asap, instead of splitting.
On Fri, Oct 11, 2013 at 9:58 PM, Keith Freeman <8f...@gmail.com> wrote:
> My route is built in parts from different spots in my code, and at one point
> I do a split:
>
> choice().when(...).bean(...).split().method(splitBean,
> "splitMethod").endChoice().otherwise().bean(...);
>
> This results in a "IllegalArgumentException: Definition has no children on
> Split...".
>
> But at this point in the code I don't know what's going to be added to the
> route, I just want the results of the split() to be forwarded down the
> route. I currently accomplish this by sticking a no-op processor into the
> route:
>
> ...split().method(...).process(new Processor() { public void
> process(Exchange e) { /* no-op */ }}).endChoice()...
>
> Which works fine, but do I really have to do this (it seems kind of ugly and
> inefficient)? Is there something better as a Camel coding idiom that's
> maybe more efficient?
--
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