日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

spring-cloud-dependencies的Edgware.RELEASE版本问题

發(fā)布時(shí)間:2025/3/17 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 spring-cloud-dependencies的Edgware.RELEASE版本问题 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

需求:由于文件上傳不僅要限時(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版本问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。