camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From /U <uma...@comcast.net>
Subject Re: onException()
Date Thu, 01 Apr 2010 06:41:23 GMT


i need to remove the route because its a transient and won't
be used again after the workflow has completed. If the route 
is simply stopped, does it get garbage collected away? won't
such stale routes accumulate and take upmemory?

also, is it expensive to perhaps create a distinct camelcontext for
each such route so the entire context can be destroyed after 
workflow is complete?

much thanks!

/U


Claus Ibsen-2 wrote:
> 
> Hi
> 
> Why do you need to remove it? Can you just stop it instead?
> The Camel in Action book, chapter 13, contains details how to stop and
> start routes at runtime.
> 
> There are methods on CamelContext to do that. Which you can easily
> invoke from a onCompletion in the route.
> 
> 
> On Thu, Apr 1, 2010 at 12:08 AM, /U <uma_rk@comcast.net> wrote:
>>
>> I studied PollingConsumerPollStrategy error handling strategies
>> and i still amnot abloe to find a way to handle errors. i think its
>> a bit strange that is done one way inside the "boundary" (i.e., after
>> the first endpoint is instantiated) and a different way thereaftr
>> (i.e., if an "interior" endpoint fails).
>>
>> in summary, I need to install an error handler to handle any permanent
>> errors with a route in the following fashion -->
>>
>>   try {
>>     from(r1).filter(mybeanfilter).to(r3).process(terminationprocessor)
>>     // terminationprocessor = remove this route from context  (1)
>>   } (if fails) {
>>      // remove this route from context  (2)
>>   }
>>
>> i need it since i need to remove the route after its done (either
>> successfully (1)
>> or unsuccessfully (2)). My terminationprocessor removes the route after a
>> successful
>> workflow. i want to be able to remove the route in case of a failed
>> workflow
>> as well.
>>
>> problem is, neither the deadLetterHandler nor the
>> PollingConsumerPollStrategy
>> error handler gets the context to the route so that i could remove it off
>> the context:
>>
>>     public class MyerrHandler implements PollingConsumerPollStrategy {
>>         public void begin(Consumer consumer, Endpoint endpoint) { ...}
>>         public void commit(Consumer consumer, Endpoint endpoint) {  ... }
>>         public boolean rollback(Consumer consumer, Endpoint endpoint, int
>> retries, Exception exception)
>>           throws Exception {
>>             // remove route that caused this failure from
>> endpoint.getContext().
>>             // but how do I know which route?
>>          }
>>    }
>>
>>     MyerrHandler errHandler = new MyerrHandler ();  // named
>> "myerrHandler"
>> in bean registry
>>     String uri2  = "ftp://server/&pollStrategy=#myerrHandler";
>>
>> Now I want access to the route that failed in myerrHandler's rollback()
>> method so I could
>> remove the route from the context.
>>
>> how i can do that?
>>
>> many thanx for any help!
>>
>> /U
>>
>>
>>
>>
>>
>>
>> Claus Ibsen-2 wrote:
>>>
>>> On Wed, Mar 24, 2010 at 11:30 PM, /U <uma_rk@comcast.net> wrote:
>>>>
>>>> thnaks for the help - it works. Only problem:
>>>> if connection to toUri fails, MyErrorhandler is
>>>> invoked; but if connection to fromUri fails,
>>>> MyErrorHandler not invoked!
>>>>
>>>> for example,
>>>>
>>>> from("file://a.log").onException(Exception.class).process(MyErrHandler).to("ftp://user@server?....").end()
>>>> is working if I cant connect to ftp server; but
>>>>
>>>>
>>>> from("ftp://user@server?....").onException(Exception.class).process(MyErrHandler).to("file://a.log").end()
>>>> not invoking MyErrHandler if server not online.
>>>>
>>>> why this difference in behavior?
>>>>
>>>
>>> Read chapter 5 in the Camel in Action book which explains error
>>> handling in great details.
>>>
>>> And see PollingConsumerPollStrategy if you want to do some custom code
>>> if the "from" fails
>>> http://camel.apache.org/polling-consumer.html
>>>
>>>>
>>>> Claus Ibsen-2 wrote:
>>>>>
>>>>> Hi
>>>>>
>>>>> onException should be set right after from. So you route should be
>>>>>
>>>>>        from(fromUri)
>>>>>           .onException(Exception.class).process(new
>>>>> MyErrorHandler(fromUri)).end();
>>>>>           .to(toUri);
>>>>>
>>>>> And you can use .toF to pass arguments (like String.format). Or its
>>>>> simply just Java so you can do .to("xxx" + "?yyy=zzz");
>>>>>
>>>>>
>>>>> On Tue, Mar 23, 2010 at 11:43 PM, /U <uma_rk@comcast.net> wrote:
>>>>>>
>>>>>> Camel: 2.2.0:
>>>>>>
>>>>>> i have route builder which adds a route as follows with a
>>>>>> deadLetterChannel
>>>>>> as a fallback error handler and an onException fork:
>>>>>>
>>>>>>
>>>>>>
>>>>>> errorHandler(deadLetterChannel("bean:myBean?method=processError"));
>>>>>>       //
>>>>>>       from(fromUri).to(toUri).end().
>>>>>>                        onException(Exception.class).process(new
>>>>>> MyErrorHandler(fromUri)).stop();
>>>>>>
>>>>>>
>>>>>> Problem is: when the message cannot be routed to the destination
>>>>>> endpoint
>>>>>> (say, because the endpoint URI is not reachable)
>>>>>> the onException nominated ErrorHandler is never invoked; instead
the
>>>>>> deadLetterChannel()
>>>>>> is invoked. This would be fine except for the fact that I need an
>>>>>> application context
>>>>>> in the error handler for cleanup: while I am able to pass the
>>>>>> required
>>>>>> context to my
>>>>>> onException error handler (as shown above), I am not sure how to
do
>>>>>> that
>>>>>> with the
>>>>>> deadLetterChannel.
>>>>>>
>>>>>> Questions:
>>>>>>   - why isn't onException() method invoked?
>>>>>>   - is there a way to pass an arbitrary data to a bean which is
used
>>>>>> as
>>>>>> an
>>>>>> endpoint. Eg:
>>>>>>         to("bean:myBean?method=processError&arg="+fromUri)
>>>>>>
>>>>>> regardds,
>>>>>>
>>>>>> /U
>>>>>>
>>>>>> --
>>>>>> View this message in context:
>>>>>> http://old.nabble.com/onException%28%29-tp28008233p28008233.html
>>>>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Claus Ibsen
>>>>> Apache Camel Committer
>>>>>
>>>>> Author of Camel in Action: http://www.manning.com/ibsen/
>>>>> Open Source Integration: http://fusesource.com
>>>>> Blog: http://davsclaus.blogspot.com/
>>>>> Twitter: http://twitter.com/davsclaus
>>>>>
>>>>>
>>>>
>>>> --
>>>> View this message in context:
>>>> http://old.nabble.com/onException%28%29-tp28008233p28022280.html
>>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> Claus Ibsen
>>> Apache Camel Committer
>>>
>>> Author of Camel in Action: http://www.manning.com/ibsen/
>>> Open Source Integration: http://fusesource.com
>>> Blog: http://davsclaus.blogspot.com/
>>> Twitter: http://twitter.com/davsclaus
>>>
>>>
>>
>> --
>> View this message in context:
>> http://old.nabble.com/onException%28%29-tp28008233p28102352.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
> 
> 
> 
> -- 
> Claus Ibsen
> Apache Camel Committer
> 
> Author of Camel in Action: http://www.manning.com/ibsen/
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
> 
> 

-- 
View this message in context: http://old.nabble.com/onException%28%29-tp28008233p28105055.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Mime
View raw message