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")
...

3 thoughts on “camel-http, Apache HttpClient, and Retry Attempts”

  1. Hello,I wanted to share http://www.RoboContacts.com with you. They have a cloud based system that is simple to use and will put your massage directly in front of your specific customer base!I hope you check it out, its trusted by over 7,000 Businesses!Thank You, www.RoboContacts.com USA Based

Leave a Reply

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