wordpress输入qq评论sem优化公司
在默认情况下 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: truemax-connections: 100max-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>