You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Wang Yan <wy...@gmail.com> on 2019/08/28 05:37:45 UTC

OnException block to figured out where the Exception is originated from

Hello all,


OnException block , the TechnicalException will be caught, this
exception could come

from Route A or Route B , my question is , Is it possible for on Exception block

to figure out where the TechnicalException is originated from ? for
example from which Route or from which Endpoint?

I tried to use exchange.getProperty(Exchange.FAILURE_ENDPOINT) or
exchange.getProperty(Exchange.FAILURE_ROUTE_ID)

but they both print out null value

Any hints or suggestions are more than welcome!




onException(TechnicalException.class)
              .log(LoggingLevel.ERROR, "TechnicalException caught globally  ")
              .redeliveryDelay(3000)
              .maximumRedeliveries(3)
              //Exchange.FAILURE_ROUTE_ID
              .onRedelivery(exchange -> {
               LOG.info("onRedelivery {} , failed endpoint id {}
exception type {}",
exchange.getIn().getHeader(Exchange.REDELIVERY_COUNTER)
         ,exchange.getProperty(Exchange.FAILURE_ENDPOINT) ,
exchange.getProperty(Exchange.EXCEPTION_CAUGHT).getClass());
              })
      .handled(true)
              .to("activemq:queue:mydeadletterqueue")
              .log(LoggingLevel.ERROR, "technical exception send to
mydeadletterqueue")
              .end();


route A

route B

Re: OnException block to figured out where the Exception is originated from

Posted by Wang Yan <wy...@gmail.com>.
Omar Al-Safi

Thank you for the clarification. it works as you suggested!

On Wed, Aug 28, 2019 at 11:31 AM Omar Al-Safi [via Camel] <
ml+s465427n5841999h75@n5.nabble.com> wrote:

> If I understood you correctly, you want to know from where this Exchange
> which holds the exception, have you tried something like
> `exchange.getFromEndpoint` or `exchange.getFromRouteId`? Which as I
> understood should gives from which endpoint this exchange has been
> originated from. However, I think `Exchange.FAILURE_ENDPOINT` will contain
> the information about the last time Camel has sent the exchange to, hence
> I
> think you would see this information after a `to` route. However I am not
> 100% sure though.
>
> On Wed, 28 Aug 2019 at 07:38, Wang Yan <[hidden email]
> <http:///user/SendEmail.jtp?type=node&node=5841999&i=0>> wrote:
>
> > Hello all,
> >
> >
> > OnException block , the TechnicalException will be caught, this
> > exception could come
> >
> > from Route A or Route B , my question is , Is it possible for on
> Exception
> > block
> >
> > to figure out where the TechnicalException is originated from ? for
> > example from which Route or from which Endpoint?
> >
> > I tried to use exchange.getProperty(Exchange.FAILURE_ENDPOINT) or
> > exchange.getProperty(Exchange.FAILURE_ROUTE_ID)
> >
> > but they both print out null value
> >
> > Any hints or suggestions are more than welcome!
> >
> >
> >
> >
> > onException(TechnicalException.class)
> >               .log(LoggingLevel.ERROR, "TechnicalException caught
> > globally  ")
> >               .redeliveryDelay(3000)
> >               .maximumRedeliveries(3)
> >               //Exchange.FAILURE_ROUTE_ID
> >               .onRedelivery(exchange -> {
> >                LOG.info("onRedelivery {} , failed endpoint id {}
> > exception type {}",
> > exchange.getIn().getHeader(Exchange.REDELIVERY_COUNTER)
> >          ,exchange.getProperty(Exchange.FAILURE_ENDPOINT) ,
> > exchange.getProperty(Exchange.EXCEPTION_CAUGHT).getClass());
> >               })
> >       .handled(true)
> >               .to("activemq:queue:mydeadletterqueue")
> >               .log(LoggingLevel.ERROR, "technical exception send to
> > mydeadletterqueue")
> >               .end();
> >
> >
> > route A
> >
> > route B
> >
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
>
> https://camel.465427.n5.nabble.com/OnException-block-to-figured-out-where-the-Exception-is-originated-from-tp5841975p5841999.html
> To unsubscribe from OnException block to figured out where the Exception
> is originated from, click here
> <https://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5841975&code=d3lhbmJveEBnbWFpbC5jb218NTg0MTk3NXwxMTU1MzAzODM=>
> .
> NAML
> <https://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>

Re: OnException block to figured out where the Exception is originated from

Posted by Omar Al-Safi <om...@gmail.com>.
If I understood you correctly, you want to know from where this Exchange
which holds the exception, have you tried something like
`exchange.getFromEndpoint` or `exchange.getFromRouteId`? Which as I
understood should gives from which endpoint this exchange has been
originated from. However, I think `Exchange.FAILURE_ENDPOINT` will contain
the information about the last time Camel has sent the exchange to, hence I
think you would see this information after a `to` route. However I am not
100% sure though.

On Wed, 28 Aug 2019 at 07:38, Wang Yan <wy...@gmail.com> wrote:

> Hello all,
>
>
> OnException block , the TechnicalException will be caught, this
> exception could come
>
> from Route A or Route B , my question is , Is it possible for on Exception
> block
>
> to figure out where the TechnicalException is originated from ? for
> example from which Route or from which Endpoint?
>
> I tried to use exchange.getProperty(Exchange.FAILURE_ENDPOINT) or
> exchange.getProperty(Exchange.FAILURE_ROUTE_ID)
>
> but they both print out null value
>
> Any hints or suggestions are more than welcome!
>
>
>
>
> onException(TechnicalException.class)
>               .log(LoggingLevel.ERROR, "TechnicalException caught
> globally  ")
>               .redeliveryDelay(3000)
>               .maximumRedeliveries(3)
>               //Exchange.FAILURE_ROUTE_ID
>               .onRedelivery(exchange -> {
>                LOG.info("onRedelivery {} , failed endpoint id {}
> exception type {}",
> exchange.getIn().getHeader(Exchange.REDELIVERY_COUNTER)
>          ,exchange.getProperty(Exchange.FAILURE_ENDPOINT) ,
> exchange.getProperty(Exchange.EXCEPTION_CAUGHT).getClass());
>               })
>       .handled(true)
>               .to("activemq:queue:mydeadletterqueue")
>               .log(LoggingLevel.ERROR, "technical exception send to
> mydeadletterqueue")
>               .end();
>
>
> route A
>
> route B
>