欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

feign的ribbon超時(shí)配置和hystrix的超時(shí)配置說(shuō)明

 更新時(shí)間:2020年09月30日 09:09:09   作者:璀璨英雄  
這篇文章主要介紹了feign的ribbon超時(shí)配置和hystrix的超時(shí)配置說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

先看下我的配置:

ribbon:

MaxAutoRetries: 1 #最大重試次數(shù),當(dāng)Eureka中可以找到服務(wù),但是服務(wù)連不上時(shí)將會(huì)重試
MaxAutoRetriesNextServer: 1 #切換實(shí)例的重試次數(shù)
OkToRetryOnAllOperations: false # 對(duì)所有的操作請(qǐng)求都進(jìn)行重試,如果是get則可以,如果是post,put等操作沒(méi)有實(shí)現(xiàn)冪等的情況下是很危險(xiǎn)的,所以設(shè)置為false
ConnectTimeout: 1000 #請(qǐng)求連接的超時(shí)時(shí)間
ReadTimeout: 1800 #請(qǐng)求處理的超時(shí)時(shí)間

hystrix:

command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds: 3000
#如果配置ribbon的重試,hystrix的超時(shí)時(shí)間要大于ribbon的超時(shí)時(shí)間,ribbon才會(huì)重試
#hystrix的超時(shí)時(shí)間=(1 + MaxAutoRetries + MaxAutoRetriesNextServer) * ReadTimeout 比較好,具體看需求

Ribbon超時(shí)與Hystrix超時(shí)問(wèn)題,為了確保Ribbon重試的時(shí)候不被熔斷,我們就需要讓Hystrix的超時(shí)時(shí)間大于Ribbon的超時(shí)時(shí)間,否則Hystrix命令超時(shí)后,該命令直接熔斷,重試機(jī)制就沒(méi)有任何意義了。

從上面的配置來(lái)說(shuō),ribbon超時(shí)配置為1800,請(qǐng)求超時(shí)后,該實(shí)例會(huì)重試1次,更新實(shí)例會(huì)重試1次。

所以hystrix的超時(shí)時(shí)間要大于 (1 + MaxAutoRetries + MaxAutoRetriesNextServer) * ReadTimeout 比較好,具體看需求進(jìn)行配置。

Ribbon超時(shí)與Hystrix超時(shí)問(wèn)題,為了確保Ribbon重試的時(shí)候不被熔斷,我們就需要讓Hystrix的超時(shí)時(shí)間大于Ribbon的超時(shí)時(shí)間,否則Hystrix命令超時(shí)后,該命令直接熔斷,重試機(jī)制就沒(méi)有任何意義了。

補(bǔ)充知識(shí):Spring Cloud Feign 第一次調(diào)用超時(shí)(Read timed out)的解決辦法

feign-client在第一次調(diào)用微服務(wù)會(huì)出現(xiàn)Read timed out異常,提示的報(bào)錯(cuò)信息:

java.net.SocketTimeoutException: Read timed out

這是由于在調(diào)用其他微服務(wù)接口前,會(huì)去請(qǐng)求該微服務(wù)的相關(guān)信息(地址、端口等),并做一些初始化操作,由于默認(rèn)的懶加載特性,導(dǎo)致了在第一次調(diào)用時(shí),出現(xiàn)超時(shí)的情況,解決方法主要有兩種:

第一種辦法是設(shè)置超時(shí)時(shí)間,具體設(shè)置成多少,因項(xiàng)目而異,配置如下:

# 全局關(guān)閉Hystrix超時(shí),對(duì)所有微服務(wù)有效
hystrix.command.default.execution.timeout.enabled: false

# 關(guān)閉某一個(gè)微服務(wù)的超時(shí)
hystrix.command.<serviceName>.execution.timeout.enabled: false

# 全局設(shè)置超時(shí)時(shí)間為60秒
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 60000

# 設(shè)置某一個(gè)微服務(wù)的超時(shí)時(shí)間為60秒
hystrix.command.<serviceName>.execution.isolation.thread.timeoutInMilliseconds: 60000

# 設(shè)置ribbon超時(shí)時(shí)間
ribbon:
ReadTimeout: 20000
ConnectTimeout: 20000

第二種辦法,也是比較推薦的方式,配置ribbon立即加載,此處需要注意的是,光配置立即加載是不生效的,還要配置客戶(hù)端列表,配置如下,詳細(xì)配置請(qǐng)點(diǎn)擊

ribbon:
eager-load:
enabled: true
clients: distribution, material-product, outer-data

最后附上未開(kāi)啟立即加載時(shí),第一次調(diào)用打印的日志:

2019-05-27 18:05:33.819|INFO|1986|http-nio-18884-exec-2|clipcloud-configuration|3752c9412075144e|3752c9412075144e|false|com.migu.clipcloud.configuration.ConfigurationServiceApplication.test1-55|time:2019-05-27 18:05:33.819
2019-05-27 18:05:33.826|INFO|1986|hystrix-distribution-1|clipcloud-configuration|3752c9412075144e|405382c2fc629614|false|com.migu.clipcloud.services.client.FeignHeadConfiguration.lambda$requestInterceptor$2-51|add request header for feignclient, key:cookie,value:JSESSIONID.8250e395=node08z98wvylx12lwh89c6v09qk92.node0; screenResolution=1440x900; m=2258:cmFiYml0bXE6cmFiYml0bXE%253D
2019-05-27 18:05:33.828|INFO|1986|hystrix-distribution-1|clipcloud-configuration|3752c9412075144e|405382c2fc629614|false|org.springframework.context.support.AbstractApplicationContext.prepareRefresh-588|Refreshing SpringClientFactory-distribution: startup date [Mon May 27 18:05:33 CST 2019]; parent: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@203dd56b
2019-05-27 18:05:33.850|INFO|1986|hystrix-distribution-1|clipcloud-configuration|3752c9412075144e|405382c2fc629614|false|org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.<init>-153|JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2019-05-27 18:05:33.864|INFO|1986|hystrix-distribution-1|clipcloud-configuration|3752c9412075144e|405382c2fc629614|false|com.netflix.config.ChainedDynamicProperty$ChainLink.checkAndFlip-115|Flipping property: distribution.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
2019-05-27 18:05:33.865|INFO|1986|hystrix-distribution-1|clipcloud-configuration|3752c9412075144e|405382c2fc629614|false|com.netflix.util.concurrent.ShutdownEnabledTimer.<init>-58|Shutdown hook installed for: NFLoadBalancer-PingTimer-distribution
2019-05-27 18:05:33.866|INFO|1986|hystrix-distribution-1|clipcloud-configuration|3752c9412075144e|405382c2fc629614|false|com.netflix.loadbalancer.BaseLoadBalancer.initWithConfig-192|Client: distribution instantiated a LoadBalancer: DynamicServerListLoadBalancer:{NFLoadBalancer:name=distribution,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:null
2019-05-27 18:05:33.884|INFO|1986|hystrix-distribution-1|clipcloud-configuration|3752c9412075144e|405382c2fc629614|false|com.netflix.loadbalancer.DynamicServerListLoadBalancer.enableAndInitLearnNewServersFeature-222|Using serverListUpdater PollingServerListUpdater
2019-05-27 18:05:33.886|INFO|1986|hystrix-distribution-1|clipcloud-configuration|3752c9412075144e|405382c2fc629614|false|com.netflix.config.ChainedDynamicProperty$ChainLink.checkAndFlip-115|Flipping property: distribution.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
2019-05-27 18:05:33.887|INFO|1986|hystrix-distribution-1|clipcloud-configuration|3752c9412075144e|405382c2fc629614|false|com.netflix.loadbalancer.DynamicServerListLoadBalancer.restOfInit-150|DynamicServerListLoadBalancer for client distribution initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=distribution,current list of Servers=[192.168.26.103:18887],Load balancer stats=Zone stats: {defaultzone=[Zone:defaultzone; Instance count:1; Active connections count: 0; Circuit breaker tripped count: 0; Active connections per server: 0.0;]
},Server stats: [[Server:192.168.26.103:18887; Zone:defaultZone; Total Requests:0; Successive connection failure:0; Total blackout seconds:0; Last connection made:Thu Jan 01 08:00:00 CST 1970; First connection made: Thu Jan 01 08:00:00 CST 1970; Active Connections:0; total failure count in last (1000) msecs:0; average resp time:0.0; 90 percentile resp time:0.0; 95 percentile resp time:0.0; min resp time:0.0; max resp time:0.0; stddev resp time:0.0]
]}ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList@173441c2
2019-05-27 18:05:33.906|INFO|1986|http-nio-18884-exec-2|clipcloud-configuration|3752c9412075144e|3752c9412075144e|false|com.migu.clipcloud.configuration.ConfigurationServiceApplication.test1-57|time:2019-05-27 18:05:33.906
2019-05-27 18:05:34.888|INFO|1986|PollingServerListUpdater-0|clipcloud-configuration||||com.netflix.config.ChainedDynamicProperty$ChainLink.checkAndFlip-115|Flipping property: distribution.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647

以上這篇feign的ribbon超時(shí)配置和hystrix的超時(shí)配置說(shuō)明就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Spring?Aop常見(jiàn)注解與執(zhí)行順序詳解

    Spring?Aop常見(jiàn)注解與執(zhí)行順序詳解

    這篇文章主要給大家介紹了關(guān)于Spring?Aop常見(jiàn)注解與執(zhí)行順序的相關(guān)資料,文中通過(guò)圖文以及實(shí)例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2022-02-02
  • SpringBoot整合EasyExcel實(shí)現(xiàn)文件導(dǎo)入導(dǎo)出

    SpringBoot整合EasyExcel實(shí)現(xiàn)文件導(dǎo)入導(dǎo)出

    這篇文章主要介紹了SpringBoot整合EasyExcel實(shí)現(xiàn)文件導(dǎo)入導(dǎo)出的方法,幫助大家更好的理解和學(xué)習(xí)使用SpringBoot,感興趣的朋友可以了解下
    2021-05-05
  • spring?batch線上異常定位記錄

    spring?batch線上異常定位記錄

    這篇文章主要為大家介紹了spring?batch線上異常定位記錄及異常解決,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步早日升職加薪
    2022-03-03
  • 淺談junit4單元測(cè)試高級(jí)用法

    淺談junit4單元測(cè)試高級(jí)用法

    這篇文章主要介紹了淺談junit4單元測(cè)試高級(jí)用法,小編覺(jué)得挺不錯(cuò)的,在這里分享給大家,需要的朋友可以參考下。
    2017-10-10
  • Spring MVC參數(shù)校驗(yàn)詳解(關(guān)于`@RequestBody`返回`400`)

    Spring MVC參數(shù)校驗(yàn)詳解(關(guān)于`@RequestBody`返回`400`)

    這篇文章主要介紹了Spring MVC參數(shù)校驗(yàn)的相關(guān)資料,主要是針對(duì)`@RequestBody`返回`400`的問(wèn)題,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面跟著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-08-08
  • JAVA獲取特定格式時(shí)間方式

    JAVA獲取特定格式時(shí)間方式

    我們有時(shí)要獲取時(shí)間,年月日時(shí)分秒周幾,有時(shí)要以特定的格式出現(xiàn),本文主要介紹了JAVA獲取特定格式時(shí)間方式,具有一定的參考價(jià)值,感興趣的可以了解一下
    2023-10-10
  • 簡(jiǎn)介Java編程中的Object類(lèi)

    簡(jiǎn)介Java編程中的Object類(lèi)

    這篇文章主要介紹了簡(jiǎn)介Java編程中的Object類(lèi),是Java入門(mén)學(xué)習(xí)中的基礎(chǔ)知識(shí),需要的朋友可以參考下
    2015-09-09
  • Java Map 按key排序和按Value排序的實(shí)現(xiàn)方法

    Java Map 按key排序和按Value排序的實(shí)現(xiàn)方法

    下面小編就為大家?guī)?lái)一篇Java Map 按key排序和按Value排序的實(shí)現(xiàn)方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2016-08-08
  • Java如何通過(guò)反射獲取Constructor、Field、Method對(duì)象

    Java如何通過(guò)反射獲取Constructor、Field、Method對(duì)象

    反射指的是對(duì)象的反向處理操作,根據(jù)對(duì)象取得對(duì)象的來(lái)源信息,在反射的世界里面,看重的不再是一個(gè)對(duì)象,而是對(duì)象身后的組成,下面這篇文章主要給大家介紹了關(guān)于Java如何通過(guò)反射獲取Constructor、Field、Method對(duì)象的相關(guān)資料,需要的朋友可以參考下
    2022-06-06
  • java中UDP簡(jiǎn)單聊天程序?qū)嵗a

    java中UDP簡(jiǎn)單聊天程序?qū)嵗a

    這篇文章主要介紹了java中UDP簡(jiǎn)單聊天程序?qū)嵗a,有需要的朋友可以參考一下
    2013-12-12

最新評(píng)論