You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Peter Maas <pf...@gmail.com> on 2009/06/10 13:09:41 UTC

end() method in a route

Hi,

I wondered what the purpose of the 'end' method in a route is. I sort  
of expected it to be a terminator for dead-end routes. But that  
doesn't seem to be the case.

If I do something like this:

from("direct:start")
	.process(new Processor(){
		public void process(Exchange arg0) throws Exception {
			System.out.println("hello!");
		}
	})
	.end();


I get the following exception:


java.lang.IllegalArgumentException: Root node with no active block
	at  
org 
.apache.camel.model.ProcessorDefinition.end(ProcessorDefinition.java: 
719)


I currently 'terminate' such a route by using a non-existent direct  
endpoint, which works but raises a WARN messages...

What is the preferred way to do this?

-P



Re: end() method in a route

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Jun 10, 2009 at 3:58 PM, Hadrian Zbarcea<hz...@gmail.com> wrote:
> I am not so sure about that.  I had the same thoughts more than a year ago,
> but I came to the conclusion that it's best the way it is, although a bit
> confusing at times for the beginner.
>
> A bit of background on this.  Initially Camel did not have explicit Block
> processors.  A Block processor is a chain of processor that sort of act like
> one.  Like a choice() for instance.  In the case of a choice() for instance,
> one could not continue processing after the choice(), regardless of what
> path in the choice().  The route ends implicitly after the last processor,
> but in the choice() case for instance meant that whatever came after
> otherwise() was the processing for the otherwise() path, and hence still
> part of choice().  And that's how the Block processor came to be.  For a
> Block processor such as choice() when end() is encountered it indicates the
> end of the otherwise() (or last when() if no otherwise()) and whatever
> follows end() will continue the processing regardless what path of choice()
> was chosen.
>
> Now there was the question of explicit end() for Block processors.  In xml
> there is no problem, as you pointed out.  In Java we had to decide to either
> enforce explicit end() or support and implicit, silent end() if there was a
> block processor, which was the case previously.  For backward compatibility
> and not to clutter the routes in simpler cases, we decided the the latter is
> the better (although not ideal) solution.
>
> Coming back to the original example, it does not need and end() as there is
> no Block processor there.  A route ends simply by not having another
> processor to send the message to.
Yeah after working a bit with this we keep it as is. It works quite
well in Java DSL as well.
Only the doTry .. doCatch .. doFinally have a little variation so we
only need a single end() to end this block. Otherwise doCatch and
doFinally would like an end as well.

So it works quite well. Just be sure to add the end() if you do
advanced routing in Java DSL in the same route.
For simplicity you can split it into multiple routes (eg add more
from) and link them using direct endpoint.




>
> My $0.02,
> Hadrian
>
>
> On Jun 10, 2009, at 7:55 AM, Claus Ibsen wrote:
>
>> On Wed, Jun 10, 2009 at 1:46 PM, Roman
>> Kalukiewicz<ro...@gmail.com> wrote:
>>>
>>> BTW The message in the Exception could be more clear. It is not
>>> obvious what "Root node with no active block" is ;)
>>
>> Yeah I have been wondering if we should force a begin DSL for the few
>> EIP types that have nested routes,
>> to easier pair begin / end and have better errors if missing.
>>
>> In Spring XML you have the XML tags start/end tag for that. So that is
>> really an area where the XML is better than Java DSL.
>>
>>
>>>
>>> Roman
>>>
>>> 2009/6/10 Claus Ibsen <cl...@gmail.com>:
>>>>
>>>> On Wed, Jun 10, 2009 at 1:09 PM, Peter Maas<pf...@gmail.com> wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>> I wondered what the purpose of the 'end' method in a route is. I sort
>>>>> of
>>>>> expected it to be a terminator for dead-end routes. But that doesn't
>>>>> seem to
>>>>> be the case.
>>>>>
>>>>> If I do something like this:
>>>>>
>>>>> from("direct:start")
>>>>>       .process(new Processor(){
>>>>>               public void process(Exchange arg0) throws Exception {
>>>>>                       System.out.println("hello!");
>>>>>               }
>>>>>       })
>>>>>       .end();
>>>>>
>>>>>
>>>>> I get the following exception:
>>>>>
>>>>>
>>>>> java.lang.IllegalArgumentException: Root node with no active block
>>>>>       at
>>>>>
>>>>> org.apache.camel.model.ProcessorDefinition.end(ProcessorDefinition.java:719)
>>>>>
>>>>>
>>>>> I currently 'terminate' such a route by using a non-existent direct
>>>>> endpoint, which works but raises a WARN messages...
>>>>>
>>>>> What is the preferred way to do this?
>>>>
>>>> Not to use end() at all.
>>>>
>>>> They should only be used for some special EIP that kinda have sub
>>>> routes, such as
>>>> - aggregator
>>>> - splitter
>>>> and a few others
>>>>
>>>> So your route should just be:
>>>>  from("direct:start")
>>>>       .process(new Processor(){
>>>>               public void process(Exchange arg0) throws Exception {
>>>>                       System.out.println("hello!");
>>>>               }
>>>>       });
>>>>
>>>>
>>>>
>>>>>
>>>>> -P
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Claus Ibsen
>>>> Apache Camel Committer
>>>>
>>>> Open Source Integration: http://fusesource.com
>>>> Blog: http://davsclaus.blogspot.com/
>>>> Twitter: http://twitter.com/davsclaus
>>>>
>>>
>>
>>
>>
>> --
>> Claus Ibsen
>> Apache Camel Committer
>>
>> Open Source Integration: http://fusesource.com
>> Blog: http://davsclaus.blogspot.com/
>> Twitter: http://twitter.com/davsclaus
>
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: end() method in a route

Posted by Hadrian Zbarcea <hz...@gmail.com>.
I am not so sure about that.  I had the same thoughts more than a year  
ago, but I came to the conclusion that it's best the way it is,  
although a bit confusing at times for the beginner.

A bit of background on this.  Initially Camel did not have explicit  
Block processors.  A Block processor is a chain of processor that sort  
of act like one.  Like a choice() for instance.  In the case of a  
choice() for instance, one could not continue processing after the  
choice(), regardless of what path in the choice().  The route ends  
implicitly after the last processor, but in the choice() case for  
instance meant that whatever came after otherwise() was the processing  
for the otherwise() path, and hence still part of choice().  And  
that's how the Block processor came to be.  For a Block processor such  
as choice() when end() is encountered it indicates the end of the  
otherwise() (or last when() if no otherwise()) and whatever follows  
end() will continue the processing regardless what path of choice()  
was chosen.

Now there was the question of explicit end() for Block processors.  In  
xml there is no problem, as you pointed out.  In Java we had to decide  
to either enforce explicit end() or support and implicit, silent end()  
if there was a block processor, which was the case previously.  For  
backward compatibility and not to clutter the routes in simpler cases,  
we decided the the latter is the better (although not ideal) solution.

Coming back to the original example, it does not need and end() as  
there is no Block processor there.  A route ends simply by not having  
another processor to send the message to.

My $0.02,
Hadrian


On Jun 10, 2009, at 7:55 AM, Claus Ibsen wrote:

> On Wed, Jun 10, 2009 at 1:46 PM, Roman
> Kalukiewicz<ro...@gmail.com> wrote:
>> BTW The message in the Exception could be more clear. It is not
>> obvious what "Root node with no active block" is ;)
> Yeah I have been wondering if we should force a begin DSL for the few
> EIP types that have nested routes,
> to easier pair begin / end and have better errors if missing.
>
> In Spring XML you have the XML tags start/end tag for that. So that is
> really an area where the XML is better than Java DSL.
>
>
>>
>> Roman
>>
>> 2009/6/10 Claus Ibsen <cl...@gmail.com>:
>>> On Wed, Jun 10, 2009 at 1:09 PM, Peter Maas<pf...@gmail.com>  
>>> wrote:
>>>> Hi,
>>>>
>>>> I wondered what the purpose of the 'end' method in a route is. I  
>>>> sort of
>>>> expected it to be a terminator for dead-end routes. But that  
>>>> doesn't seem to
>>>> be the case.
>>>>
>>>> If I do something like this:
>>>>
>>>> from("direct:start")
>>>>        .process(new Processor(){
>>>>                public void process(Exchange arg0) throws  
>>>> Exception {
>>>>                        System.out.println("hello!");
>>>>                }
>>>>        })
>>>>        .end();
>>>>
>>>>
>>>> I get the following exception:
>>>>
>>>>
>>>> java.lang.IllegalArgumentException: Root node with no active block
>>>>        at
>>>> org 
>>>> .apache 
>>>> .camel.model.ProcessorDefinition.end(ProcessorDefinition.java:719)
>>>>
>>>>
>>>> I currently 'terminate' such a route by using a non-existent direct
>>>> endpoint, which works but raises a WARN messages...
>>>>
>>>> What is the preferred way to do this?
>>> Not to use end() at all.
>>>
>>> They should only be used for some special EIP that kinda have sub
>>> routes, such as
>>> - aggregator
>>> - splitter
>>> and a few others
>>>
>>> So your route should just be:
>>>  from("direct:start")
>>>        .process(new Processor(){
>>>                public void process(Exchange arg0) throws Exception {
>>>                        System.out.println("hello!");
>>>                }
>>>        });
>>>
>>>
>>>
>>>>
>>>> -P
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> Claus Ibsen
>>> Apache Camel Committer
>>>
>>> Open Source Integration: http://fusesource.com
>>> Blog: http://davsclaus.blogspot.com/
>>> Twitter: http://twitter.com/davsclaus
>>>
>>
>
>
>
> -- 
> Claus Ibsen
> Apache Camel Committer
>
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus


Re: end() method in a route

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Jun 10, 2009 at 1:46 PM, Roman
Kalukiewicz<ro...@gmail.com> wrote:
> BTW The message in the Exception could be more clear. It is not
> obvious what "Root node with no active block" is ;)
Yeah I have been wondering if we should force a begin DSL for the few
EIP types that have nested routes,
to easier pair begin / end and have better errors if missing.

In Spring XML you have the XML tags start/end tag for that. So that is
really an area where the XML is better than Java DSL.


>
> Roman
>
> 2009/6/10 Claus Ibsen <cl...@gmail.com>:
>> On Wed, Jun 10, 2009 at 1:09 PM, Peter Maas<pf...@gmail.com> wrote:
>>> Hi,
>>>
>>> I wondered what the purpose of the 'end' method in a route is. I sort of
>>> expected it to be a terminator for dead-end routes. But that doesn't seem to
>>> be the case.
>>>
>>> If I do something like this:
>>>
>>> from("direct:start")
>>>        .process(new Processor(){
>>>                public void process(Exchange arg0) throws Exception {
>>>                        System.out.println("hello!");
>>>                }
>>>        })
>>>        .end();
>>>
>>>
>>> I get the following exception:
>>>
>>>
>>> java.lang.IllegalArgumentException: Root node with no active block
>>>        at
>>> org.apache.camel.model.ProcessorDefinition.end(ProcessorDefinition.java:719)
>>>
>>>
>>> I currently 'terminate' such a route by using a non-existent direct
>>> endpoint, which works but raises a WARN messages...
>>>
>>> What is the preferred way to do this?
>> Not to use end() at all.
>>
>> They should only be used for some special EIP that kinda have sub
>> routes, such as
>> - aggregator
>> - splitter
>> and a few others
>>
>> So your route should just be:
>>  from("direct:start")
>>        .process(new Processor(){
>>                public void process(Exchange arg0) throws Exception {
>>                        System.out.println("hello!");
>>                }
>>        });
>>
>>
>>
>>>
>>> -P
>>>
>>>
>>>
>>
>>
>>
>> --
>> Claus Ibsen
>> Apache Camel Committer
>>
>> Open Source Integration: http://fusesource.com
>> Blog: http://davsclaus.blogspot.com/
>> Twitter: http://twitter.com/davsclaus
>>
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: end() method in a route

Posted by Roman Kalukiewicz <ro...@gmail.com>.
BTW The message in the Exception could be more clear. It is not
obvious what "Root node with no active block" is ;)

Roman

2009/6/10 Claus Ibsen <cl...@gmail.com>:
> On Wed, Jun 10, 2009 at 1:09 PM, Peter Maas<pf...@gmail.com> wrote:
>> Hi,
>>
>> I wondered what the purpose of the 'end' method in a route is. I sort of
>> expected it to be a terminator for dead-end routes. But that doesn't seem to
>> be the case.
>>
>> If I do something like this:
>>
>> from("direct:start")
>>        .process(new Processor(){
>>                public void process(Exchange arg0) throws Exception {
>>                        System.out.println("hello!");
>>                }
>>        })
>>        .end();
>>
>>
>> I get the following exception:
>>
>>
>> java.lang.IllegalArgumentException: Root node with no active block
>>        at
>> org.apache.camel.model.ProcessorDefinition.end(ProcessorDefinition.java:719)
>>
>>
>> I currently 'terminate' such a route by using a non-existent direct
>> endpoint, which works but raises a WARN messages...
>>
>> What is the preferred way to do this?
> Not to use end() at all.
>
> They should only be used for some special EIP that kinda have sub
> routes, such as
> - aggregator
> - splitter
> and a few others
>
> So your route should just be:
>  from("direct:start")
>        .process(new Processor(){
>                public void process(Exchange arg0) throws Exception {
>                        System.out.println("hello!");
>                }
>        });
>
>
>
>>
>> -P
>>
>>
>>
>
>
>
> --
> Claus Ibsen
> Apache Camel Committer
>
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
>

Re: end() method in a route

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Jun 10, 2009 at 1:09 PM, Peter Maas<pf...@gmail.com> wrote:
> Hi,
>
> I wondered what the purpose of the 'end' method in a route is. I sort of
> expected it to be a terminator for dead-end routes. But that doesn't seem to
> be the case.
>
> If I do something like this:
>
> from("direct:start")
>        .process(new Processor(){
>                public void process(Exchange arg0) throws Exception {
>                        System.out.println("hello!");
>                }
>        })
>        .end();
>
>
> I get the following exception:
>
>
> java.lang.IllegalArgumentException: Root node with no active block
>        at
> org.apache.camel.model.ProcessorDefinition.end(ProcessorDefinition.java:719)
>
>
> I currently 'terminate' such a route by using a non-existent direct
> endpoint, which works but raises a WARN messages...
>
> What is the preferred way to do this?
Not to use end() at all.

They should only be used for some special EIP that kinda have sub
routes, such as
- aggregator
- splitter
and a few others

So your route should just be:
 from("direct:start")
        .process(new Processor(){
                public void process(Exchange arg0) throws Exception {
                        System.out.println("hello!");
                }
        });



>
> -P
>
>
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus