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組件,不然重試不會生效
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章