Quantcast

Exception handling with Hystrix EIP

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Exception handling with Hystrix EIP

Priyanka Gopinath
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Exception handling with Hystrix EIP

Abhishek.Jha09
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.
Loading...