springboot feign-httpclient 连接池配置
在默认情况下 spring cloud feign 在进行各个子服务之间的调用时,http组件使用的是jdk的HttpURLConnection,没有使用线程池。有2种可选的线程池:HttpClient 和 OKHttp
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId></dependency><dependency><groupId>io.github.openfeign</groupId><artifactId>feign-okhttp</artifactId></dependency>
在Spring Boot项目中使用Feign并配置HttpClient连接池,application.yml
文件中添加相关配置。
如果你使用的是application.yml
,配置如下:
feign:httpclient:enabled: truemax-connections: 100max-connections-per-route: 20
或
feign:okhttp:enabled: truehttpclient: #统一的配置参数,无论是httpclient还是okhttpclient都可以connection-timeout: 8000max-connections: 2
更多的参数设置参考FeignHttpClientProperties
类