当前位置:网站首页>【微服务|OpenFeign】openfeign的超时时间
【微服务|OpenFeign】openfeign的超时时间
2022-06-29 07:16:00 【步尔斯特】
我当前所用的spring cloud 版本为Hoxton.SR9,从spring-cloud-2020.0.0 开始移除了诸多Netflix组件,这里只是为了更好的应用ribbon。
因为该版本openfeign内部整合了ribbon,故可以通过对ribbon的配置来达到更改openfeign的超时时间等。
spring-cloud-2020.0.0版本开始,这种配置即失效,可通过更改Request.Options,以达到ribbon这种效果。
全局配置
ribbon方式修改超时时间
#设置feign客户端超时时间(OpenFeign默认支持ribbon)
ribbon:
#指的是建立连接所用的时间,适用于网络状况正常的情况下,两端连接所用的时间
ReadTimeout: 5000
#指的是建立连接后从服务器读取到可用资源所用的时间
ConnectTimeout: 5000
Request.Options方式修改超时时间
问题:if the request should follow 3xx redirections.
配置类方式
import feign.Request;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.concurrent.TimeUnit;
/** * @author issavior */
@Configuration
public class FeignOptionsConfig {
/** * 超时时间配置 */
@Bean
public Request.Options options() {
return new Request.Options(5, TimeUnit.SECONDS,
5, TimeUnit.SECONDS, true);
}
配置文件方式
feign:
client:
config:
# 提供方的服务名
default:
#请求日志级别
loggerLevel: FULL
#设置为默认的契约(还原成原生注解)
# contract: feign.Contract.Default
# 连接超时时间,默认2s,设置单位为毫秒
connectTimeout: 5000
# 请求处理超时时间,默认5s,设置单位为毫秒。
readTimeout: 5000
局部配置
feign:
client:
config:
# 提供方的服务名
ossa-service-producer:
#请求日志级别
loggerLevel: FULL
#设置为默认的契约(还原成原生注解)
# contract: feign.Contract.Default
# 连接超时时间,默认2s,设置单位为毫秒
connectTimeout: 5000
# 请求处理超时时间,默认5s,设置单位为毫秒。
readTimeout: 5000
源码解析
相关源码梳理【我只截了几张源码图,我相信你们这些老粉都一定可以看懂 //狗头保命】
这里首先进行初始化,默认连接和读取的时间都为1000毫秒,加载进内存中。



如果配置文件中,有ribbon相关配置,则刷新/覆盖内存中相应的值。



边栏推荐
- Basic syntax - bit operation
- Excel中VLOOKUP函数简易使用——精确匹配或近似匹配数据
- Ceres optimization based on sophus
- SVM, problems encountered in face recognition and Solutions
- MySQL statistics by day / week / month / quarter / half year / year
- C mqtt subscription message
- solidity部署和验证代理合约
- 在iframe标签中操作外层dom
- Program debugging - debug/release version
- 壁纸小程序源码双端微信抖音小程序
猜你喜欢

互联网公司的组织结构与产品经理岗位职责是什么?

语音信号处理-基础(一):声学基础知识

Excel中VLOOKUP函数简易使用——精确匹配或近似匹配数据

1284_ Implementation analysis of FreeRTOS task priority acquisition

手撕二叉搜索树(Binary Search Tree)

VMware vcenter/esxi series vulnerability summary

1284_FreeRTOS任务优先级获取实现分析

Segment tree and use

在colaboratory上云端使用GPU训练(以YOLOv5举例)

产品经理应该学习墨刀还是Axure?
随机推荐
C compiler - implicit function declaration
图文详解JVM中的垃圾回收机制(GC)
华为云的AI深潜之旅
友元,静态关键字,静态方法以及对象间的关系
Reflection perfectionism
SizeBalanceTree
x86和x64的区别
智能硬件evt dvt pvt mp
马赛克笔记
1284_ Implementation analysis of FreeRTOS task priority acquisition
Verilog first experience
【kerberos】kerberos 认证浅析
Application of mediastreamer2 and GStreamer in embedded field
NOR flash application layer operation
穿越过后,她说多元宇宙真的存在
Program debugging - debug/release version
手撕二叉搜索树(Binary Search Tree)
关于SQL语句的大小写
Protobuf binary file learning and parsing
Sonic communication - streaming data processing - window alignment