Open Feign对HTTP请求做了优化,并且可以提供了多种客户端选择,来优化HTTP请求发起,以下是HTTP请求支持的三种方式
HttpURLConnection:默认实现,不支持连接池
Apache HTTPClient:支持连接池
OKHttp:支持连接池
OKHttp:
相关依赖
XML<!--OK http 的依赖 --> <dependency> <groupId>io.github.openfeign</groupId> <artifactId>feign-okhttp</artifactId> </dependency>
添加配置
XMLfeign: okhttp: enabled: true client: config: default: connect-timeout: 5000 #连接超时时间 read-timeout: 5000 #读超时时间 logger-level: basic #日志级别
HttpClient:
相关依赖:
XML<!--feign httpclient--> <dependency> <groupId>io.github.openfeign</groupId> <artifactId>feign-httpclient</artifactId> </dependency>
添加配置:
XMLfeign: httpclient: enabled: true client: config: default: logger-level: basic # 日志级别 connect-timeout: 5000 # 连接超时 单位ms read-timeout: 5000 # 读取超时 单位ms