1. 程式人生 > >zuul閘道器配置請求併發以及重試

zuul閘道器配置請求併發以及重試

介紹

Zuul預設整合hystrix, 同時,和hystrix一樣採用執行緒隔離技術
zuul預設使用:訊號量(semaphore)
hystrix預設使用:執行緒池 (thread)

配置訊號量

屬性 描述
zuul.ribbon-isolation-strategy semaphore 配置隔離策略為訊號量
zuul.semaphore.max-semaphores 1000 配置訊號量大小
hystrix.command.default.execution.isolation.strategy semaphore 配置斷路器中的隔離策略為訊號量
hystrix.command.default.execution.isolation.semaphore.maxConcurrentRequests 1000 配置斷路器中的訊號量大小

沒有測試過,只配置zuul是否生效, 或者2個配置不同,哪一個配置生效

重試

1.5.6
使用Ribbon zuul hystrix

引入重試jar包

<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
</dependency>
  
  • 1
  • 2
  • 3
  • 4

參考 LoadBalancerAutoConfiguration 以及RibbonAutoConfiguration
實現原理: RetryLoadBalancerInterceptor 實現 ClientHttpRequestInterceptor

通過攔截器實現

配置

屬性 描述 預設值
spring.cloud.loadbalancer.retry.enabled ture 開啟重試機制 true
zuul.retryable true 如果使用zuul,需要配置該屬性 false
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds 8000 如果使用ribbon和hystrix,設定超時時間 1000
ribbon.OkToRetryOnAllOperations true 是否所有的操作都重試 false
ribbon.MaxAutoRetriesNextServer 2 重試負載均衡其他例項的最大重試次數,不包括首次例項 0
ribbon.MaxAutoRetries 0 同一臺例項的最大重試次數,不包括首次呼叫 0
ribbon.ConnectTimeout 1000 http建立socket超時時間
ribbon.ReadTimeout 3000 http讀取響應socket超時時間

注意:
- ribbon.ConnectTimeout+ribbon.ReadTimeout<hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds
- 連線失敗的意思是服務宕機,請求不可到達, 並不是服務報錯