springboot feign-httpclient 连接池配置
在默认情况下 spring cloud feign 在进行各个子服务之间的调用时,http组件使用的是jdk的HttpURLConnection,没有使用线程池。有2种可选的线程池:HttpClient 和 OKHttp
在Spring Boot项目中使用Feign并配置HttpClient连接池,你需要在application.properties
或application.yml
文件中添加相关配置。
以下是application.properties
中的配置示例:
# 设置Feign使用HttpClient
feign.httpclient.enabled=true
# 设置HttpClient的连接管理器参数
feign.httpclient.max-connections=100
feign.httpclient.max-connections-per-route=20
或者,如果你使用的是application.yml
,配置如下:
feign:
httpclient:
enabled: true
max-connections: 100
max-connections-per-route: 20
或
feign:
okhttp:
enabled: true
# feign最大连接数
max-connections: 200
# feign单个路径的最大连接数
max-connections-per-route: 50
确保你的项目中已经添加了Feign和HttpClient的依赖:
<!-- Feign客户端依赖 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<!-- HttpClient依赖 -->
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-httpclient</artifactId>
</dependency>
或者
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-okhttp</artifactId>
<version>11.0</version>
</dependency>
原文地址:https://blog.csdn.net/nsa65223/article/details/142861333
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!