How to set custom max connection pool size in @feignclient configuration in spring

Ankush Nakaskar picture Ankush Nakaskar · Apr 11, 2018 · Viewed 7.9k times · Source

How to set custom max connection pool size in @feignclient configuration in spring ,

@FeignClient(name = "content-cms", configuration = ContentCmsServiceFeignConfig.class)
public interface FeignService {

@RequestMapping(value = "/test/", method = RequestMethod.GET)
String getSample(@RequestParam("token") String token, @RequestParam("cid") String cid,
        @RequestParam("ratio") String ratio, @RequestParam("s") String source);

}

Answer

Kevin Davis picture Kevin Davis · Apr 25, 2018

You can configure the number of connections within the specific Client implementation used. Feign has out of the box support Apache Http, OkHttp and Ribbon. When using Spring Cloud Open Feign, the default client is based on what you have in your classpath.

Here is an example using Apache Http, you can configure your own CloseableHttpClient bean with the settings you want.

@Configuration
public class HttpClientConfiguration {
    @Bean
    public CloseableHttpClient httpClient() {
       return HttpClients.custom()
                  .maxConnectionsPerRoute(200)
                  .maxConnections(200)
                  .build()
    }
} 

If you are using Spring Boot, you can configure any of the feign.httpclient.* properties as well.

feign:
   httpclient:
       maxConnections: 200
       maxConnectionsPerRoute: 200

You can find more information in the Spring Cloud OpenFeign Documentation: Overriding Feign Defaults