You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Priyanka Gopinath <pr...@karnam.net> on 2017/03/20 23:51:54 UTC

Exception handling with Hystrix EIP

Hi,



I am trying to enable hystrix in our camel application and I am trying to
understand how the exceptions are dealt when using the Hystrix EIP .

When we set the timeOut to a smaller value than the endpoint call, there is
no exception thrown that we can deal with. I need a handle to this
exception so that I can clean up some data and fail the transaction
gracefully. The process stops abruptly. What am I  missing here? Is there a
different way to handle this?





from("direct:hystrixSlowEndpoint")

.hystrix()

.hystrixConfiguration().executionTimeoutInMilliseconds(2000).groupKey("my-key").end()

.log("Before call to endpoint")

.to("direct:slow")

.log("After call to endpoint")

.end()

.log("After Hystrix ${body}");

from("direct:slow")

.log("Slow processing start: ${threadName}")

.delay(3000)

.transform().constant("Slow response")

.log("Slow processing end: ${threadName}");


Log excerpt -

2017-03-20 16:47:48,927 [ystrix-my-key-1] INFO
 rixRouteBuilderTest$mySlowTest - Before Log[Hystrix processing start:
${threadName}] with body null

2017-03-20 16:47:48,927 [ystrix-my-key-1] INFO  route4
    - Hystrix processing start: hystrix-my-key-1

2017-03-20 16:47:48,929 [ystrix-my-key-1] INFO
 rixRouteBuilderTest$mySlowTest - Before To[direct:slow] with body null

2017-03-20 16:47:48,930 [ystrix-my-key-1] INFO
 rixRouteBuilderTest$mySlowTest - Before Log[Slow processing start:
${threadName}] with body null

2017-03-20 16:47:48,930 [ystrix-my-key-1] INFO  route5
    - Slow processing start: hystrix-my-key-1

2017-03-20 16:47:48,930 [ystrix-my-key-1] INFO
 rixRouteBuilderTest$mySlowTest - Before Delay[{3000} ->
[Transform[constant{Slow response}], Log[Slow processing end:
${threadName}]]] with body null

2017-03-20 16:47:50,939 [main           ] INFO
 rixRouteBuilderTest$mySlowTest -
********************************************************************************

2017-03-20 16:47:50,939 [main           ] INFO
 rixRouteBuilderTest$mySlowTest - Testing done:
null(HystrixRouteBuilderTest$mySlowTest)

2017-03-20 16:47:50,939 [main           ] INFO
 rixRouteBuilderTest$mySlowTest - Took: 2.191 seconds (2191 millis)

2017-03-20 16:47:50,939 [main           ] INFO
 rixRouteBuilderTest$mySlowTest -
********************************************************************************

2017-03-20 16:47:50,943 [main           ] INFO  DefaultCamelContext
   - Apache Camel 2.18.1 (CamelContext: camel-2) is shutting down

Re: Exception handling with Hystrix EIP

Posted by Priyanka Gopinath <pr...@karnam.net>.
Thanks for the response Abhishek. I was using version 2.18. The release
notes mentions that there is a bug in the hystrix fallback  implementation.
However, upon moving to v2.18.3, it worked magically!

On Wed, Mar 22, 2017 at 9:17 PM, Abhishek.Jha09 <ab...@gmail.com> wrote:

> Hi Priyanka,
>
> So, as it happens, the exceptions captured by hystrix are present as a
> property of the exchange if fallback is defined otherwise, you can get it
> directly from exchange. Try peeking inside exchange.getProperties() and
> after you trigger the route and exchange.getException().
>
> FYI, here's the logs generated in my case-
>
>
> 09:39| INFO | CamelLogger.java 159 | Before call to endpoint
> 09:39| INFO | CamelLogger.java 159 | Slow processing start:
> hystrix-my-key-1
> {CamelMessageHistory=[DefaultMessageHistory[routeId=route1,
> node=hystrix1],
> DefaultMessageHistory[routeId=route1, node=log1],
> DefaultMessageHistory[routeId=route1, node=to1],
> DefaultMessageHistory[routeId=route2, node=log4],
> DefaultMessageHistory[routeId=route2, node=delay1]],
> CamelCorrelationId=***********, CamelCreatedTimestamp=************,
> CamelRouteStop=true, CamelToEndpoint=direct://slow}
> com.netflix.hystrix.exception.HystrixRuntimeException: hystrix1 timed-out
> and no fallback available.
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.
> com/Exception-handling-with-Hystrix-EIP-tp5795811p5795991.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Exception handling with Hystrix EIP

Posted by "Abhishek.Jha09" <ab...@gmail.com>.
Hi Priyanka,

So, as it happens, the exceptions captured by hystrix are present as a
property of the exchange if fallback is defined otherwise, you can get it
directly from exchange. Try peeking inside exchange.getProperties() and
after you trigger the route and exchange.getException().

FYI, here's the logs generated in my case-


09:39| INFO | CamelLogger.java 159 | Before call to endpoint
09:39| INFO | CamelLogger.java 159 | Slow processing start: hystrix-my-key-1
{CamelMessageHistory=[DefaultMessageHistory[routeId=route1, node=hystrix1],
DefaultMessageHistory[routeId=route1, node=log1],
DefaultMessageHistory[routeId=route1, node=to1],
DefaultMessageHistory[routeId=route2, node=log4],
DefaultMessageHistory[routeId=route2, node=delay1]],
CamelCorrelationId=***********, CamelCreatedTimestamp=************,
CamelRouteStop=true, CamelToEndpoint=direct://slow}
com.netflix.hystrix.exception.HystrixRuntimeException: hystrix1 timed-out
and no fallback available.




--
View this message in context: http://camel.465427.n5.nabble.com/Exception-handling-with-Hystrix-EIP-tp5795811p5795991.html
Sent from the Camel - Users mailing list archive at Nabble.com.