Spring Cloud in Feign client is enabled by default to support the Ribbon, the most important is the two time-out connection timeout ConnectTimeout and read timeout ReadTimeout , by default, that is, without any configuration, Feign timeout will be overwritten Ribbon, two time-out time is 1 second.
Simply put a scene here, not on the code, app-user service calls app-order service interface, and then set the delay 1.5s in the app-order interface, the call to see the effect:
Wrong call, the console display read timeout, this is because Ribbon default timeout is 1s caused. As long as we look at this configuration timeout on the line:
Ribbon Global Configuration
Add yml configuration profile of the caller, set the timeout to 5s:
ribbon:
#建立连接超时时间
ConnectTimeout: 5000
#建立连接之后,读取响应资源超时时间
ReadTimeout: 5000
Then restart the service, the call is successful
Feign Configuration
Note: Feign configuration takes precedence over the Ribbon configuration. The same effect Once you've configured.
feign:
client:
config:
#这里填具体的服务名称(也可以填default,表示对所有服务生效)
app-order:
#connectTimeout和readTimeout这两个得一起配置才会生效
connectTimeout: 5000
readTimeout: 5000