总结:
1.配置zuul.routes.<路由规则> 如果路由规则和存在的服务应用名是一致的serviceID可以不用配置
2.配置服务的ribbon超时时间应该 小于 hystrix 时间,否则ribbon超时失效
3.服务配置的 ribbon.ReadTimeout: 30000 超过30s 会执行 implements FallbackProvider 自定义的兜底方法
application.yml配置文件
spring:
profiles:
active: dev
application:
name: zuul-gateway
servlet:
multipart:
max-file-size: 1048576
max-request-size: 1048576
file-size-threshold: 1024
location: /
zuul:
host: #如果路由方式是serviceId的方式,那么ribbon的生效,如果是url的方式,则zuul.host开头的生效。
maxTotalConnections : 20000
connection-request-timeout-millis: 12000
socketTimeoutMillis: 12000
connect-timeout-millis: 12000
ribbon:
eager-load:
enabled: true
ribbon:
eager-load:
enabled: true
hystrix:
command:
user-manager-service:
execution:
isolation:
thread:
timeoutInMilliseconds: 100000
data-upload-service:
execution:
isolation:
thread:
timeoutInMilliseconds: 100000
user-manager-service:
ribbon:
NIWSServerListClassName: com.netflix.loadbalancer.ConfigurationBasedServerList
ConnectTimeout: 20000
ReadTimeout: 30000
MaxTotalHttpConnections: 500
MaxConnectionsPerHost: 100
配置服务的ribbon超时时间 小于 hystrix 时间,否则ribbon超时失效
user-manager-service:
ribbon:
NIWSServerListClassName: com.netflix.loadbalancer.ConfigurationBasedServerList
ConnectTimeout: 20000
ReadTimeout: 30000 #超过30s服务超时(认为服务挂掉了)
MaxTotalHttpConnections: 500
MaxConnectionsPerHost: 100
application-dev.yml
#单例模式启动zuul Server
server:
port: 8101 #启动端口
max-http-header-size: 10485760
spring:
mvc:
static-path-pattern: /**
resources:
static-locations: classpath:/static/,classpath:/public/,file:${img.path.prifix}
img:
path:
prifix: C:/image
zuul:
#为zuul设置一个公共的前缀
prefix: /baas/api
stripPrefix: false
host:
connect-timeout-millis: 120000 #HTTP连接超时要比Hystrix的大
socket-timeout-millis: 120000 #socket超时
routes:
user-manager-service: #自定义的路由规则名 与服务应用名一致 可以不配置serviceId
path: /base/user/** #映射到服务的应用名为user-manager-service的服务
stripPrefix: false #
sensitiveHeaders:
user-manager-service 服务的应用名 与自定义的路由规则名一致 可以不配置serviceId
spring:
application:
name: data-upload-service