如何在spring的@feignclient
配置中设置自定义最大连接池大小,
@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);
}
最佳答案
您可以在使用的特定Client
实现中配置连接数。 Feign 开箱即用地支持 Apache Http
、OkHttp
和 Ribbon
。使用 Spring Cloud Open Feign
时,默认客户端基于类路径中的内容。
这里是一个使用 Apache Http
的例子,你可以用你想要的设置来配置你自己的 CloseableHttpClient
bean。
@Configuration
public class HttpClientConfiguration {
@Bean
public CloseableHttpClient httpClient() {
return HttpClients.custom()
.maxConnectionsPerRoute(200)
.maxConnections(200)
.build()
}
}
如果您使用的是 Spring Boot,您还可以配置任何 feign.httpclient.*
属性。
feign:
httpclient:
maxConnections: 200
maxConnectionsPerRoute: 200
您可以在 Spring Cloud OpenFeign Documentation: Overriding Feign Defaults 中找到更多信息
关于java - 如何在 spring @feignclient 配置中设置自定义最大连接池大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49779354/