Return-Path: Delivered-To: apmail-camel-users-archive@www.apache.org Received: (qmail 69088 invoked from network); 1 Apr 2010 07:59:51 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 1 Apr 2010 07:59:51 -0000 Received: (qmail 29345 invoked by uid 500); 1 Apr 2010 07:59:51 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 29266 invoked by uid 500); 1 Apr 2010 07:59:49 -0000 Mailing-List: contact users-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@camel.apache.org Delivered-To: mailing list users@camel.apache.org Received: (qmail 29166 invoked by uid 99); 1 Apr 2010 07:59:48 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Apr 2010 07:59:48 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of claus.ibsen@gmail.com designates 209.85.218.223 as permitted sender) Received: from [209.85.218.223] (HELO mail-bw0-f223.google.com) (209.85.218.223) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Apr 2010 07:59:42 +0000 Received: by bwz23 with SMTP id 23so709652bwz.36 for ; Thu, 01 Apr 2010 00:59:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :from:date:received:message-id:subject:to:content-type :content-transfer-encoding; bh=nRzGxnUH34cBGCq/+mFaXY7v2mX/TIDr4UZUmdJLKw0=; b=MH6Ghd+i4skCMSsVJLDBRfxLcZmwFj48gZ/zH9yo1aWPLgFR+FNVsGGq6hCXp+06LK 85IUjBOCoMl9VwFsC48oF1GWry8ZKSNqseJvQDqy1mR/t//Xz4NHZ78H7PlhoXcg+O/5 hpzAtprr3uQftw7hvh9LbfletSFm8NPdhgFKg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=ZQm8z+PifLGDE2ogw4S9Qj2jmlYHxS1ywAEQZoUG8S5TFvwerfKLZxz/FYR383icIc C1JXxUbDWnAZyAnFO5XDFevcuZnce3UWgycnjBI8XL7N9V2933HcDd2NkRJvSRA5I0lN p+PhE/CkybYwhAfKC2Xu3087XFy2nqyn+cHqU= MIME-Version: 1.0 Received: by 10.204.59.137 with HTTP; Thu, 1 Apr 2010 00:59:02 -0700 (PDT) In-Reply-To: <28105055.post@talk.nabble.com> References: <28008233.post@talk.nabble.com> <5380c69c1003232229v2609db1coc7af170c1ac934bf@mail.gmail.com> <28022280.post@talk.nabble.com> <5380c69c1003242245h24c75992u98e38ee44c9df6dd@mail.gmail.com> <28102352.post@talk.nabble.com> <28105055.post@talk.nabble.com> From: Claus Ibsen Date: Thu, 1 Apr 2010 09:59:02 +0200 Received: by 10.204.35.139 with SMTP id p11mr864672bkd.178.1270108762158; Thu, 01 Apr 2010 00:59:22 -0700 (PDT) Message-ID: Subject: Re: onException() To: users@camel.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org Your route looks simple, why dont you just use a POJO and use the Camels ProducerTemplate and ConsumerTemplate to send/receive. And do the filter in the POJO as well. You can use Camel Predicate to evaluate the Exchange. Then you do NOT need a route at all and hence dont need to worry about removing it from Camel. On Thu, Apr 1, 2010 at 8:41 AM, /U wrote: > > > 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 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 --> >>> >>> =A0 try { >>> =A0 =A0 from(r1).filter(mybeanfilter).to(r3).process(terminationprocess= or) >>> =A0 =A0 // terminationprocessor =3D remove this route from context =A0(= 1) >>> =A0 } (if fails) { >>> =A0 =A0 =A0// remove this route from context =A0(2) >>> =A0 } >>> >>> 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 o= ff >>> the context: >>> >>> =A0 =A0 public class MyerrHandler implements PollingConsumerPollStrateg= y { >>> =A0 =A0 =A0 =A0 public void begin(Consumer consumer, Endpoint endpoint)= { ...} >>> =A0 =A0 =A0 =A0 public void commit(Consumer consumer, Endpoint endpoint= ) { =A0... } >>> =A0 =A0 =A0 =A0 public boolean rollback(Consumer consumer, Endpoint end= point, int >>> retries, Exception exception) >>> =A0 =A0 =A0 =A0 =A0 throws Exception { >>> =A0 =A0 =A0 =A0 =A0 =A0 // remove route that caused this failure from >>> endpoint.getContext(). >>> =A0 =A0 =A0 =A0 =A0 =A0 // but how do I know which route? >>> =A0 =A0 =A0 =A0 =A0} >>> =A0 =A0} >>> >>> =A0 =A0 MyerrHandler errHandler =3D new MyerrHandler (); =A0// named >>> "myerrHandler" >>> in bean registry >>> =A0 =A0 String uri2 =A0=3D "ftp://server/&pollStrategy=3D#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 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(MyErrHandle= r).to("ftp://user@server?....").end() >>>>> is working if I cant connect to ftp server; but >>>>> >>>>> >>>>> from("ftp://user@server?....").onException(Exception.class).process(M= yErrHandler).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 >>>>>> >>>>>> =A0 =A0 =A0 =A0from(fromUri) >>>>>> =A0 =A0 =A0 =A0 =A0 .onException(Exception.class).process(new >>>>>> MyErrorHandler(fromUri)).end(); >>>>>> =A0 =A0 =A0 =A0 =A0 .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=3Dzzz"); >>>>>> >>>>>> >>>>>> On Tue, Mar 23, 2010 at 11:43 PM, /U 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=3DprocessError")= ); >>>>>>> =A0 =A0 =A0 // >>>>>>> =A0 =A0 =A0 from(fromUri).to(toUri).end(). >>>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0onException(Exceptio= n.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 th= e >>>>>>> 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: >>>>>>> =A0 - why isn't onException() method invoked? >>>>>>> =A0 - is there a way to pass an arbitrary data to a bean which is u= sed >>>>>>> as >>>>>>> an >>>>>>> endpoint. Eg: >>>>>>> =A0 =A0 =A0 =A0 to("bean:myBean?method=3DprocessError&arg=3D"+fromU= ri) >>>>>>> >>>>>>> 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-tp2= 8008233p28105055.html > Sent from the Camel - Users mailing list archive at Nabble.com. > > --=20 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