@Bean
public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
return restTemplateBuilder
.setConnectTimeout(...)
.setReadTimeout(...)
.build();
}Ribbon超时时间#全局超时配置
ribbon:
ReadTimeout: 2000 #默认5s
ConnectTimeout: 1000 #默认2s
#针对具体的服务配置
service-id:
ribbon:
ReadTimeout: 1000
ConnectTimeout: 1000Feign超时时间feign:
client:
config:
default:
connectTimeout: 5000 #默认10s
readTimeout: 5000 #默认60s
loggerLevel: basicFeign的默认超时时间在Request.Options中设置的。hystrix:
command:
default:
execution:
timeout:
enabled: true #默认true
isolation:
thread:
timeoutInMilliseconds: 5000Hystrix作为熔断器,通常其他组件一起使用时(如Ribbon)://伪代码调用方式
hystrix(retry(ribbon()))
此时需要将超时时间设置成比其他组件的长,否则重试机制将失效。Zuul超时时间zuul:
routes:
service-id:
path: /test/**
serviceId: SERVICE-ID
admin:
path: /admin/**
url: http://test.com/admin
host: #针对直接发起URL请求的超时配置(不经Ribbon)
max-total-connections: 5000
max-per-route-connections: 500
#针对Hystrix的超时配置
hystrix:
command:
default:
execution:
timeout:
enabled: true
isolation:
thread:
timeoutInMilliseconds: 5000
#针对Ribbon的超时配置
ribbon:
ReadTimeout: 1500
ConnectTimeout: 1000如果错误地将Hystrix超时配置成2s,而Ribbon配置成5s,那么在每次请求都会看到类似于下面的警告:2019年01月19日 17:39:20.981 WARN 36568 --- [io-60362-exec-9] o.s.c.n.z.f.r.s.AbstractRibbonCommand : The Hystrix timeout of 2000ms for the command SERVICE-ID is set lower than the combination of the Ribbon read and connect timeout, 12000ms.
ThinkPHP 是一个免费开源的,快速、简单的面向对象的 轻量级PHP开发框架 ,创立于2006年初,遵循Apache2开源协议发布,是为了敏捷WEB应用开发和简化企业应用开发而诞生的。ThinkPHP从诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,也注重易用性。并且拥有众多的原创功能和特性,在社区团队的积极参与下,在易用性、扩展性和性能方面不断优化和改进,已经成长为国内最领先和最具影响力的WEB应用开发框架,众多的典型案例确保可以稳定用于商业以及门户级的开发。