spring-cloud-dependencies的Edgware.RELEASE版本问题
需求:由于文件上傳不僅要限時(shí)大小,還要單獨(dú)的設(shè)置接口最大的超時(shí)時(shí)間,于是想到了改網(wǎng)關(guān)的Hystrix,Ribbon,超時(shí)時(shí)間,一開始設(shè)想的是通過網(wǎng)關(guān)來控制文件上傳接口的請(qǐng)求超時(shí)時(shí)間為120S,而同服務(wù)內(nèi)的其他接口超時(shí)時(shí)間還是原來的10秒。
?
后來,在測(cè)試中發(fā)現(xiàn):目前項(xiàng)目(Edgware.RELEASE版本)配置的Hystrix超時(shí)時(shí)間配置不起作用,不管怎么設(shè)置,Hystrix都被設(shè)置成2秒超時(shí)了,我設(shè)置的代碼如下:
hystrix:command:default: # 默認(rèn)用default,控制所有走網(wǎng)關(guān)的服務(wù)。如果你想為某個(gè)特定的service配熔斷超時(shí)策略,配置方式如下:hystrix.command.<serviceName>.execution.isolation.thread.timeoutInMilliseconds=60000execution:timeout:enabled: true # 默認(rèn)是開啟的isolation:thread:timeoutInMilliseconds: 12000 # 斷路器的超時(shí)時(shí)間(默認(rèn)1000毫秒),下級(jí)服務(wù)返回超出熔斷器時(shí)間,即便成功,消費(fèi)端消息也是TIMEOUT,所以一般斷路器的超時(shí)時(shí)間需要大于ribbon的超時(shí)時(shí)間。如果hystrixTimeout小于ribbonTimeout,可能在Ribbon切換實(shí)例進(jìn)行重試的過程中就會(huì)觸發(fā)熔斷。# 對(duì)某服務(wù)設(shè)置單獨(dú)的超時(shí)時(shí)間ulegal-system:execution:isolation:thread:timeoutInMilliseconds: 125000 # 125s不管是對(duì)'default'的配置還是對(duì)某服務(wù)'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了,才發(fā)現(xiàn)配置在實(shí)例化默認(rèn)值確實(shí)是1,但是設(shè)置值是2,排除是自己設(shè)置因素,就剩下版本問題了。
升級(jí)版本后解決:
?
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-hystrix</artifactId><version>Edgware.SR6</version></dependency>================================分界線===============================
為什么低版本的Hystrix配置不生效,分析底層源碼:
入口:AbstractRibbonCommand 類 的 getSetter()方法是獲取ribbon和hystix的超時(shí)時(shí)間的。 withExecutionTimeoutInMilliseconds(RibbonClientConfiguration.DEFAULT_CONNECT_TIMEOUT + RibbonClientConfiguration.DEFAULT_READ_TIMEOUT); 此處Hystrix被寫死獲取了ribbon 的默認(rèn)值1+1=2,所以被設(shè)置了是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}?
新人創(chuàng)作打卡挑戰(zhàn)賽發(fā)博客就能抽獎(jiǎng)!定制產(chǎn)品紅包拿不停!總結(jié)
以上是生活随笔為你收集整理的spring-cloud-dependencies的Edgware.RELEASE版本问题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux 多级目录查找,Linux如何
- 下一篇: OJ1001: 植树问题