Zuul2 超时设置 重试 踩坑

背景:

承接上一篇博客,针对的ZUUL2的超时 重试机制,踩坑了一下

配置如下

logging:
  level:
    root: info

demo-service:
  ribbon:
#      ReadTimeout: 7000
#      ConnectTimeout: 5800
#      MaxAutoRetries: 3
#      MaxAutoRetriesNextServer: 0
#      retryableStatusCodes: 500,502,503,404
      listOfServers: localhost:8002
#      OkToRetryOnAllOperations: true


zuul:
  retryable: true
  eureka:
    client:
      enabled: false
  routes:
    demo-service:
      path: /service/**
      serviceId: demo-service
#  host:
#    socket-timeout-millis: 5000
#    connect-timeout-millis: 4000
  sensitive-headers: Access-Control-Allow-Origin,Access-Control-Allow-Methods

ribbon:
  ReadTimeout: 5000
  ConnectTimeout: 1000
  MaxAutoRetries: 5
  MaxAutoRetriesNextServer: 0
#  retryableStatusCodes: 500,502,503

坑点:
  • 通过源码调试,在 HttpClientRibbonConfiguration类的retryableRibbonLoadBalancingHttpClient方法,可以看到默认的RetryableRibbonLoadBalancingHttpClient实例,主要属性的大小写,不然不会生效
  • ConnectTimeout 实际生效数值是配置的2倍,所以你配置1秒,实际是2秒,切记!!!
  • 记得引入spring-retry组件,不然重试不会生效

你可能感兴趣的:(Zuul2 超时设置 重试 踩坑)