9

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);

}
Vladislav Kysliy
  • 3,488
  • 3
  • 32
  • 44
Ankush Nakaskar
  • 121
  • 1
  • 2
  • 8

1 Answers1

14

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

Kevin Davis
  • 1,193
  • 8
  • 14
  • 3
    In order to complete this answer with a detail that kept me struggling for a whole day: you need to add a bridge between Feign and Apache HttpClient. e.g.: ` io.github.openfeign feign-httpclient ` – Jose Jurado Mar 12 '19 at 10:38
  • 1
    link corrupted. Maybe is this? https://cloud.spring.io/spring-cloud-netflix/multi/multi_spring-cloud-feign.html – WesternGun Mar 22 '19 at 08:59