3

I would like to implement Apache Camel route with retry and Hystrix circuit breaker. My route looks like this:

<route>
......
  <onException>
        <exception>java.lang.Exception</exception>
        <redeliveryPolicy  redeliveryDelay="150" maximumRedeliveries="3" logRetryAttempted="true" retryAttemptedLogLevel="WARN"/>
  </onException>
  <hystrix>
        <hystrixConfiguration id="MyServiceHystrix" />
        <to uri="{{my.service.endpoint}}?bridgeEndpoint=true"/>
  </hystrix>
</route>

When camel http4 endpoint is called inside Hystrix command thread, the CamelInternalProcessor does not call RedeliveryErrorHandler and there is no retry. The basically the stack trace deference is:

at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:542)
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:120)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)
    at org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:62)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:120)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)

Does anybody know why this happens? Can I combine both without splitting the route?

Anton Krosnev
  • 3,964
  • 1
  • 21
  • 37

1 Answers1

0

This could be helpful for others in designing the retry logic.

Camel had .circuitBreaker().inheritErrorHandler(true) but this is not working any more. (https://camel.apache.org/manual/latest/hystrix-eip.html), also the .loadbalancer().circuitBreaker() is deprecated. Pasting the code base.

/** @deprecated */
@Deprecated
public LoadBalanceDefinition circuitBreaker(int threshold, long halfOpenAfter, Class<?>... exceptions)

However, we can add the line below to retry in case of an exception.

onException(Exception.class)
.maximumRedeliveries(5) //No of times
.redeliveryDelay(1000); //Delay between retries in ms.

Here in the example above it will retry for all exceptions, however, we can narrow the retry logic to target a specific exception by replacing the Exception.class to something which your program is targetting like NullPointerException.class or MyCustomException.class

UPDATE: Missed your question completely. I pretty much wrote in Java DSL what you did using XML. Ignore!!

MMR
  • 33
  • 7