欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

SpringCloud各組件超時(shí)

Ribbon的超時(shí)

東臺(tái)網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián)公司,東臺(tái)網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為東臺(tái)成百上千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站制作要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的東臺(tái)做網(wǎng)站的公司定做!

全局設(shè)置:

ribbon: ReadTimeout: 60000 ConnectTimeout: 60000

局部設(shè)置:

service-id: ribbon: ReadTimeout: 1000 ConnectTimeout: 1000

其中,service-id 是Ribbon所使用的虛擬主機(jī)名,一般和Eureka Server上注冊(cè)的服務(wù)名稱一致,即:與spring.application.name 一致。

Feign的超時(shí)

從Spring Cloud Edgware開始,F(xiàn)eign支持使用屬性配置超時(shí):

feign: client: config: feignName: connectTimeout: 5000 readTimeout: 5000

對(duì)于老版本,可以寫個(gè)feign.Request.Options ,參考:org.springframework.cloud.netflix.feign.ribbon.FeignRibbonClientAutoConfiguration#feignRequestOptions 的寫法即可。

RestTemplate的超時(shí)

一些時(shí),我們可能使用了RestTemplate,例如

@Bean @LoadBalanced public RestTemplate restTemplate() { return new RestTemplate(); }

此時(shí),超時(shí)可使用如下方式設(shè)置:

@Bean @LoadBalanced public RestTemplate restTemplate() { SimpleClientHttpRequestFactory simpleClientHttpRequestFactory = new SimpleClientHttpRequestFactory(); simpleClientHttpRequestFactory.setConnectTimeout(1000); simpleClientHttpRequestFactory.setReadTimeout(1000); return new RestTemplate(simpleClientHttpRequestFactory); } Zuul的超時(shí)

Zuul的超時(shí)比較復(fù)雜,因?yàn)閆uul整合了Ribbon、Hystrix。下面分兩種情況討論:

如果Zuul的路由使用了Ribbon

那么:Zuul的超時(shí)則與Ribbon、Hystrix相關(guān),此時(shí)Zuul的超時(shí)可以配置類似如下:

hystrix: command: default: execution: isolation: thread: timeoutInMilliseconds: 1000 ribbon: ReadTimeout: 1000 ConnectTimeout: 1000

代碼解析:此種情況下,Zuul轉(zhuǎn)發(fā)所使用的過濾器是org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter ,在這個(gè)過濾器中,整合了Hystrix以及Ribbon。

如果Zuul的路由未使用Ribbon

例如:Zuul的路由配置如下:

zuul: routes: user-route: # 該配置方式中,user-route只是給路由一個(gè)名稱,可以任意起名。 url: http://localhost:8000/ # 指定的url path: /user/** # url對(duì)應(yīng)的路徑。

那么,此時(shí)Zuul的超時(shí)只與如下兩個(gè)配置有關(guān):

zuul: host: socket-timeout-millis: 10000 connect-timeout-millis: 2000

代碼解析:直接配置URL路由的方式,用不上Ribbon,也用不上Hystrix,Zuul轉(zhuǎn)發(fā)所使用的過濾器是org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilter ,在這個(gè)過濾器中,Zuul使用Apache HttpClient進(jìn)行轉(zhuǎn)發(fā)。

在現(xiàn)實(shí)場(chǎng)景中,有時(shí)候可能兩種路由方式配合使用,因此,建議大家配置以上所有屬性。

Hystrix的超時(shí)

hystrix: command: default: execution: timeout: enabled: true isolation: thread: timeoutInMilliseconds: 1000

如上,Hystrix的默認(rèn)超時(shí)時(shí)間是1秒。默認(rèn)開啟超時(shí)機(jī)制。如需關(guān)閉Hystrix的超時(shí),可將xxx.enabled設(shè)置為false。

Tips

如有組件跟Hystrix配合使用,一般來講,建議Hystrix的超時(shí) > 其他組件的超時(shí),否則將可能導(dǎo)致重試特性失效。

當(dāng)前題目:SpringCloud各組件超時(shí)
URL標(biāo)題:http://chinadenli.net/article46/cpcjeg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站標(biāo)簽優(yōu)化服務(wù)器托管網(wǎng)站改版品牌網(wǎng)站建設(shè)網(wǎng)站設(shè)計(jì)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

營(yíng)銷型網(wǎng)站建設(shè)