You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by David Karlsen <da...@gmail.com> on 2012/12/01 10:51:38 UTC

Re: how to break out of a batch?

 AFAIK you can end() the route as shown here:

http://camel.apache.org/predicate.html
Den 30. nov. 2012 01:22 skrev "bung_ho" <bu...@hotmail.com> følgende:

> Using camel 2.10.
>
> I have a route similar to the following:
>
>                 <route>
>                         <from uri="file:c:/cameldata/a?doneFileName=GO">
>                         <doTry>
>                         <to uri="bean:utilBean?method=doStuff"/>
>                                 <doCatch>
>
> <exception>java.lang.Exception</exception>
>
> <handled><constant>false</constant></handled>
>                                         <to
> uri="bean:utilBean?method=doFailStuff"/>
>                                 </doCatch>
>                         </doTry>
>                 </route>
>
> If multiple files are placed in the directory, then the doneFile GO is
> placed in it, it will process all of the files sequentially, each going
> thru
> the route. Normally this is good.
>
> However, what I want to do is stop the batch if there is an exception with
> one of the files as caught by the <doTry><doCatch>.  Right now, it catches
> the exception and executes "doFailStuff" but it proceeds to process the
> remaining files happily, but I don't want that -- I want the entire route
> to
> give up there. Is there a way?
>
> Hope that's clear.
>
> Thanks
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/how-to-break-out-of-a-batch-tp5723425.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: how to break out of a batch?

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Dec 4, 2012 at 2:57 AM, Willem jiang <wi...@gmail.com> wrote:
> I think we could add some feature on the ScheduledPollConsumer to stop processing the message if some kind of flag is set. As current implementation doesn't check if there is some exception is thrown  when processing the exchange.
>

I logged a ticket to track this
https://issues.apache.org/jira/browse/CAMEL-5941

> BTW, I just found the File component support the option of "maxMessagesPerPoll". It could be more easy to stop the route if the maxMessagesPerPoll=1.
>
>
> --
> Willem Jiang
>
> Red Hat, Inc.
> FuseSource is now part of Red Hat
> Web: http://www.fusesource.com | http://www.redhat.com
> Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
>           http://jnn.javaeye.com (http://jnn.javaeye.com/) (Chinese)
> Twitter: willemjiang
> Weibo: willemjiang
>
>
>
>
>
> On Tuesday, December 4, 2012 at 7:01 AM, Christian Müller wrote:
>
>> I don't think you really want to stop the route (the route will no longer
>> polling for files and process these files).
>> I think you want to stop processing the exchange (the file) which is
>> faulty. In this case, you can use stop().
>>
>> https://svn.apache.org/repos/asf/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RouteStopTest.java
>>
>> Best,
>> Christian
>>
>> On Mon, Dec 3, 2012 at 4:52 PM, bung_ho <bung_ho@hotmail.com (mailto:bung_ho@hotmail.com)> wrote:
>>
>> > static
>
>



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: how to break out of a batch?

Posted by Willem jiang <wi...@gmail.com>.
I think we could add some feature on the ScheduledPollConsumer to stop processing the message if some kind of flag is set. As current implementation doesn't check if there is some exception is thrown  when processing the exchange.

BTW, I just found the File component support the option of "maxMessagesPerPoll". It could be more easy to stop the route if the maxMessagesPerPoll=1.
  

--  
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.javaeye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: willemjiang





On Tuesday, December 4, 2012 at 7:01 AM, Christian Müller wrote:

> I don't think you really want to stop the route (the route will no longer
> polling for files and process these files).
> I think you want to stop processing the exchange (the file) which is
> faulty. In this case, you can use stop().
>  
> https://svn.apache.org/repos/asf/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RouteStopTest.java
>  
> Best,
> Christian
>  
> On Mon, Dec 3, 2012 at 4:52 PM, bung_ho <bung_ho@hotmail.com (mailto:bung_ho@hotmail.com)> wrote:
>  
> > static  



Re: how to break out of a batch?

Posted by Christian Müller <ch...@gmail.com>.
I don't think you really want to stop the route (the route will no longer
polling for files and process these files).
I think you want to stop processing the exchange (the file) which is
faulty. In this case, you can use stop().

https://svn.apache.org/repos/asf/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RouteStopTest.java

Best,
Christian

On Mon, Dec 3, 2012 at 4:52 PM, bung_ho <bu...@hotmail.com> wrote:

> static

Re: how to break out of a batch?

Posted by bung_ho <bu...@hotmail.com>.
Claus Ibsen-2 wrote
> On Sun, Dec 2, 2012 at 4:52 PM, bung_ho &lt;

> bung_ho@

> &gt; wrote:
>> Thanks, but are you sure end() is being used to end the route there? It's
>> not
>> clear to me and I can't find any more documentation on end() anywhere. I
>> saw
>> this other example and it doesn't look like it's being used to end the
>> route
>> prematurely the way I'd like to. Note that in the XML version, there is
>> no
>> such "end" tag.
>>
>> http://fusesource.com/docs/router/2.2/eip/BasicPrinciples-ExceptionHandling-doTry.html
>>
>> I'd like to try it but I can't find any equivalent way to do it in XML,
>> which is what we are using.
>>
> 
> I think he refers to 
> <stop/>
> . Which will stop continue routing an exchange.
> 
> 
> About the end, then its only available in Java DSL, because you need
> it in situations to denote an endpoint ro an eip.
> For example in XML you have
> <split>
>   ...
>   ...
> </split>
> And where 
> </split>
>  marks the end of the split. In Java you can use
> .end() for that instead
> 
> split()
>   ...
>   ...
> .end()

Thanks Claus, that makes sense.

I did read about doing stop() or stopRoute() but it seems that it is not
advisable to do so from within the route itself, and that it is suggested to
instead use a different route that calls stopRoute on the route I want to
stop. However this becomes an asynchronous operation -- but I want to make
sure that the route doesn't continue even 1 step on the other files, from
the moment of the exception. It seems that stopping the route asynchronously
from another route wouldn't guarantee this.

Instead, I came up with a crude workaround. What I did was to use a bean to
carry a static flag (actually a Hashtable of flags, containing a status for
each different route). If one file fails processing, it sets the flag to an
error condition. Then each subsequent iteration of the route (i.e., each
run-thru for subsequent files in the batch) would check this flag and act
accordingly (continue processing or not). Admittedly it is crude but it
serves my purposes and since the route should only be run by one thread at
any given time, seems reasonably safe to me.

Is there a better way to do what I'm trying to do? (I also tried to use
Exchange properties and even ThreadLocal variables instead of the static
flag, but those get reset for each run-thru of the route).

Thanks



--
View this message in context: http://camel.465427.n5.nabble.com/how-to-break-out-of-a-batch-tp5723425p5723550.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: how to break out of a batch?

Posted by Claus Ibsen <cl...@gmail.com>.
On Sun, Dec 2, 2012 at 4:52 PM, bung_ho <bu...@hotmail.com> wrote:
> Thanks, but are you sure end() is being used to end the route there? It's not
> clear to me and I can't find any more documentation on end() anywhere. I saw
> this other example and it doesn't look like it's being used to end the route
> prematurely the way I'd like to. Note that in the XML version, there is no
> such "end" tag.
>
> http://fusesource.com/docs/router/2.2/eip/BasicPrinciples-ExceptionHandling-doTry.html
>
> I'd like to try it but I can't find any equivalent way to do it in XML,
> which is what we are using.
>

I think he refers to <stop/>. Which will stop continue routing an exchange.


About the end, then its only available in Java DSL, because you need
it in situations to denote an endpoint ro an eip.
For example in XML you have

<split>
  ...
  ...
</split>

And where </split> marks the end of the split. In Java you can use
.end() for that instead

split()
  ...
  ...
.end()



>
> David J. M. Karlsen wrote
>> AFAIK you can end() the route as shown here:
>>
>> http://camel.apache.org/predicate.html
>> Den 30. nov. 2012 01:22 skrev "bung_ho" <
>
>> bung_ho@
>
>> > følgende:
>>
>>> Using camel 2.10.
>>>
>>> I have a route similar to the following:
>>>
>>>
>> <route>
>>>
>> <from uri="file:c:/cameldata/a?doneFileName=GO">
>>>
>> <doTry>
>>>
>> <to uri="bean:utilBean?method=doStuff"/>
>>>
>> <doCatch>
>>>
>>>
>> <exception>
>> java.lang.Exception
>> </exception>
>>>
>>>
>> <handled>
>> <constant>
>> false
>> </constant>
>> </handled>
>>>
>> <to
>>>
>>  uri="bean:utilBean?method=doFailStuff"/>
>>>
>> </doCatch>
>>>
>> </doTry>
>>>
>> </route>
>>>
>>> If multiple files are placed in the directory, then the doneFile GO is
>>> placed in it, it will process all of the files sequentially, each going
>>> thru
>>> the route. Normally this is good.
>>>
>>> However, what I want to do is stop the batch if there is an exception
>>> with
>>> one of the files as caught by the
>> <doTry>
>> <doCatch>
>> .  Right now, it catches
>>> the exception and executes "doFailStuff" but it proceeds to process the
>>> remaining files happily, but I don't want that -- I want the entire route
>>> to
>>> give up there. Is there a way?
>>>
>>> Hope that's clear.
>>>
>>> Thanks
>>>
>>>
>>>
>>> --
>>> View this message in context:
>>> http://camel.465427.n5.nabble.com/how-to-break-out-of-a-batch-tp5723425.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/how-to-break-out-of-a-batch-tp5723425p5723503.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: how to break out of a batch?

Posted by bung_ho <bu...@hotmail.com>.
Thanks, but are you sure end() is being used to end the route there? It's not
clear to me and I can't find any more documentation on end() anywhere. I saw
this other example and it doesn't look like it's being used to end the route
prematurely the way I'd like to. Note that in the XML version, there is no
such "end" tag. 

http://fusesource.com/docs/router/2.2/eip/BasicPrinciples-ExceptionHandling-doTry.html

I'd like to try it but I can't find any equivalent way to do it in XML,
which is what we are using.


David J. M. Karlsen wrote
> AFAIK you can end() the route as shown here:
> 
> http://camel.apache.org/predicate.html
> Den 30. nov. 2012 01:22 skrev "bung_ho" &lt;

> bung_ho@

> &gt; følgende:
> 
>> Using camel 2.10.
>>
>> I have a route similar to the following:
>>
>>                 
> <route>
>>                         
> <from uri="file:c:/cameldata/a?doneFileName=GO">
>>                         
> <doTry>
>>                         
> <to uri="bean:utilBean?method=doStuff"/>
>>                                 
> <doCatch>
>>
>> 
> <exception>
> java.lang.Exception
> </exception>
>>
>> 
> <handled>
> <constant>
> false
> </constant>
> </handled>
>>                                         
> <to
>>
>  uri="bean:utilBean?method=doFailStuff"/>
>>                                 
> </doCatch>
>>                         
> </doTry>
>>                 
> </route>
>>
>> If multiple files are placed in the directory, then the doneFile GO is
>> placed in it, it will process all of the files sequentially, each going
>> thru
>> the route. Normally this is good.
>>
>> However, what I want to do is stop the batch if there is an exception
>> with
>> one of the files as caught by the 
> <doTry>
> <doCatch>
> .  Right now, it catches
>> the exception and executes "doFailStuff" but it proceeds to process the
>> remaining files happily, but I don't want that -- I want the entire route
>> to
>> give up there. Is there a way?
>>
>> Hope that's clear.
>>
>> Thanks
>>
>>
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/how-to-break-out-of-a-batch-tp5723425.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>





--
View this message in context: http://camel.465427.n5.nabble.com/how-to-break-out-of-a-batch-tp5723425p5723503.html
Sent from the Camel - Users mailing list archive at Nabble.com.