當前位置:
首頁 >
spring-cloud-dependencies的Edgware.RELEASE版本问题
發布時間:2025/3/17
53
豆豆
生活随笔
收集整理的這篇文章主要介紹了
spring-cloud-dependencies的Edgware.RELEASE版本问题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
需求:由于文件上傳不僅要限時大小,還要單獨的設置接口最大的超時時間,于是想到了改網關的Hystrix,Ribbon,超時時間,一開始設想的是通過網關來控制文件上傳接口的請求超時時間為120S,而同服務內的其他接口超時時間還是原來的10秒。
?
后來,在測試中發現:目前項目(Edgware.RELEASE版本)配置的Hystrix超時時間配置不起作用,不管怎么設置,Hystrix都被設置成2秒超時了,我設置的代碼如下:
hystrix:command:default: # 默認用default,控制所有走網關的服務。如果你想為某個特定的service配熔斷超時策略,配置方式如下:hystrix.command.<serviceName>.execution.isolation.thread.timeoutInMilliseconds=60000execution:timeout:enabled: true # 默認是開啟的isolation:thread:timeoutInMilliseconds: 12000 # 斷路器的超時時間(默認1000毫秒),下級服務返回超出熔斷器時間,即便成功,消費端消息也是TIMEOUT,所以一般斷路器的超時時間需要大于ribbon的超時時間。如果hystrixTimeout小于ribbonTimeout,可能在Ribbon切換實例進行重試的過程中就會觸發熔斷。# 對某服務設置單獨的超時時間ulegal-system:execution:isolation:thread:timeoutInMilliseconds: 125000 # 125s不管是對'default'的配置還是對某服務'ulegal-system'的配置,均不起作用。
一開始是懷疑spring-cloud-starter-netflix-hystrix依賴沒有引入,重新檢查了一遍Hystrix的依賴,確定是有引入的。百思不得其解
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-hystrix</artifactId><version>Edgware.RELEASE</version></dependency>后來Debug了,才發現配置在實例化默認值確實是1,但是設置值是2,排除是自己設置因素,就剩下版本問題了。
升級版本后解決:
?
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-hystrix</artifactId><version>Edgware.SR6</version></dependency>================================分界線===============================
為什么低版本的Hystrix配置不生效,分析底層源碼:
入口:AbstractRibbonCommand 類 的 getSetter()方法是獲取ribbon和hystix的超時時間的。 withExecutionTimeoutInMilliseconds(RibbonClientConfiguration.DEFAULT_CONNECT_TIMEOUT + RibbonClientConfiguration.DEFAULT_READ_TIMEOUT); 此處Hystrix被寫死獲取了ribbon 的默認值1+1=2,所以被設置了是2秒。 protected static Setter getSetter(final String commandKey,ZuulProperties zuulProperties) {// @formatter:offSetter commandSetter = Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("RibbonCommand")).andCommandKey(HystrixCommandKey.Factory.asKey(commandKey));final HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter().withExecutionIsolationStrategy(zuulProperties.getRibbonIsolationStrategy()).withExecutionTimeoutInMilliseconds(RibbonClientConfiguration.DEFAULT_CONNECT_TIMEOUT + RibbonClientConfiguration.DEFAULT_READ_TIMEOUT);if (zuulProperties.getRibbonIsolationStrategy() == ExecutionIsolationStrategy.SEMAPHORE){final String name = ZuulConstants.ZUUL_EUREKA + commandKey + ".semaphore.maxSemaphores";// we want to default to semaphore-isolation since this wraps// 2 others commands that are already thread isolatedfinal DynamicIntProperty value = DynamicPropertyFactory.getInstance().getIntProperty(name, zuulProperties.getSemaphore().getMaxSemaphores());setter.withExecutionIsolationSemaphoreMaxConcurrentRequests(value.get());} else if (zuulProperties.getThreadPool().isUseSeparateThreadPools()) {final String threadPoolKey = zuulProperties.getThreadPool().getThreadPoolKeyPrefix() + commandKey;commandSetter.andThreadPoolKey(HystrixThreadPoolKey.Factory.asKey(threadPoolKey));}return commandSetter.andCommandPropertiesDefaults(setter);// @formatter:on}?
新人創作打卡挑戰賽發博客就能抽獎!定制產品紅包拿不停!總結
以上是生活随笔為你收集整理的spring-cloud-dependencies的Edgware.RELEASE版本问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux 多级目录查找,Linux如何
- 下一篇: OJ1001: 植树问题