camel-http, Apache HttpClient, and Retry Attempts

Morning!  Here’s a quick tip on camel-http and proper retry logic within error handling.  Under the hood, camel-http uses Apache’s HttpClient, which provides its own retry logic by default.  Adding Camel’s onException redeliveries on top of that ends up multiplying the attempts.



onException(ConnectException.class)
  .maximumRedeliveries(3)
  ...
;
...
  .to(“http://this.site.does.not.exist.com?bridgeEndpoint=true&httpClient.soTimeout=10000")
...

By default, the above will actually be reattempted 9 times, not 3!

So, we need to choose one or the other. I’d recommend disabling the retries on HttpClient, allowing the Camel redelivery policies to be setup like all the others (consistency FTW). That requires registering a HttpClientConfigurer bean, then referring to it on your http step.

@Bean
public HttpClientConfigurer noRetryHttpConfigurer() {
  return new HttpClientConfigurer() {
    @Override
    public void configureHttpClient(HttpClient client) {
      client.getParams().setParameter("http.method.retry-handler", new DefaultHttpMethodRetryHandler(0, false));
    }
  };
}
...
  .to(“http://this.site.does.not.exist.com?bridgeEndpoint=true&httpClient.soTimeout=10000&httpClientConfigurer=noRetryHttpConfigurer")
...

2 Replies to “camel-http, Apache HttpClient, and Retry Attempts”

Leave a Reply

Your email address will not be published. Required fields are marked *