camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Hoffer <dhoff...@gmail.com>
Subject Re: Camel exception handling
Date Tue, 07 Nov 2017 17:51:44 GMT
I did find the problem and the solution.

The problem is that Camel always rolled back the file at the from SFTP URI
so the entire route is repeated indefinitely.  There was no way (I could
find) to configure Camel to break out of this route with an exception when
the unmarshal bean threw an exception.  The solution was to add another
sub-route where the first just moved the file from SFTP to the local hard
drive (e.g. no beans that can throw here).  Then with the file on the local
hard drive I created a second file URI route that picked up that same file
with the moveFailed parameter (moveFailed did not work on SFTP URI).  Now
since Camel can actually 'handle' the error by moving the file on error it
does not do any retries and the exception handler works as expected.  Also
same for the JMX part it recorded the failure as expected in this second
route.

Ideally it seems that if the SFTP endpoint could be configured to fail on
errors the same could have been accomplished w/o the second route.  However
I have no problem with the second route as it lets me 'save' a copy of the
bad file for later possible analysis.

-Dave

On Tue, Nov 7, 2017 at 8:36 AM, Claus Ibsen <claus.ibsen@gmail.com> wrote:

> You cannot do that, but you can track the failures handled attribute
> in JMX which we be incremented when you handle that exception.
>
>
> On Mon, Nov 6, 2017 at 8:22 PM, David Hoffer <dhoffer6@gmail.com> wrote:
> > I’m having trouble getting the exception behavior I’m looking for.  What
> I
> > expected this to do is when any exception is thrown it will cause this
> > route to fail and not do any retries as the docs say that no
> > onException retries is the default.
> >
> > However instead it retries forever as long as the handled constant is
> > false.  Only when I set that to true do I get the expected behavior but I
> > don’t want to do that because then our Camel JMX tool that monitors all
> > routes will report this as a success which is exactly wrong.
> >
> > I tried added a redeliveryPolicy where maximumRedeliveries=0 and that
> does
> > not help.
> >
> >
> > Specifically the source of the exception that is being thrown is in each
> of
> > the unmarshal beans, e.g. tarGz, tar, etc.
> >
> >
> > <route id="from_OD" autoStartup="{{gp.camel.OD.from.isConfigured}}"
> >             <from uri="sftp://{{gp.camel.OD.from.username}}@
> > {{gp.camel.OD.from.host}}:{{gp.camel.OD.from.port}}?
> password={{gp.camel.OD.from.password}}&amp;delete=true&
> amp;exclusiveReadLockStrategy=#nonBlockingSftpReadLockStrateg
> y&amp;readLockCheckInterval=10000&amp;readLockTimeout=
> 3600000&amp;reconnectDelay=10000&amp;delay=10000"/>
> >
> >             <convertBodyTo type="byte[]"/>
> >
> >             <choice>
> >                 <when id="tarGz">
> >                     <simple>${file:name} regex '.*\.tgz'</simple>
> >                     <unmarshal ref="tarGz"/>
> >                     <split>
> >                         <simple>${header.CamelGroupedExchange}</simple>
> >                         <bean ref="routeManager" method="route(*)"/>
> >                     </split>
> >                 </when>
> >                 <when id="tar.gz">
> >                     <simple>${file:name} regex '.*\.tar\.gz'</simple>
> >
> >                     <unmarshal ref="tarGz"/>
> >                     <split>
> >                         <simple>${header.CamelGroupedExchange}</simple>
> >                         <bean ref="routeManager" method="route(*)"/>
> >                     </split>
> >                 </when>
> >                 <when id="tar">
> >                     <simple>${file:name} regex '.*\.tar'</simple>
> >                     <unmarshal ref="tar"/>
> >                     <split>
> >                         <simple>${header.CamelGroupedExchange}</simple>
> >                         <bean ref="routeManager" method="route(*)"/>
> >                     </split>
> >                 </when>
> >                 <when id="gz">
> >                     <simple>${file:name} regex '.*\.gz'</simple>
> >                     <unmarshal ref="gz"/>
> >                     <split>
> >                         <simple>${header.CamelGroupedExchange}</simple>
> >                         <bean ref="routeManager" method="route(*)"/>
> >                     </split>
> >                 </when>
> >                 <when id="zip">
> >                     <simple>${file:name} regex '.*\.zip'</simple>
> >                     <unmarshal ref="zip"/>
> >                     <split>
> >                         <simple>${header.CamelGroupedExchange}</simple>
> >                         <bean ref="routeManager" method="route(*)"/>
> >                     </split>
> >                 </when>
> >                 <otherwise>
> >                     <stop/>
> >                 </otherwise>
> >             </choice>
> >     <onException>
> >                 <exception>java.lang.Exception</exception>
> > <redeliveryPolicy maximumRedeliveries="0"/>
> >                 <handled>
> >                     <constant>false</constant>
> >                 </handled>
> >                 <log loggingLevel="ERROR" message="onException during
> > from_OD :  ${exception.message}\n${exception.stacktrace}"/>
> > <to
> > uri="file://{{gangplank.share_home}}/work/fromOD/.error/?
> tempFileName=${file:name}.partial"/>
> >             </onException>
> >         </route>
> >
> > Any ideas why I get what seems like the opposite of the expected behavior
> > and how to fix?
> >
> > -Dave
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message