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

feign的ribbon超時配置和hystrix的超時配置說明

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

先看下我的配置:

ribbon:

MaxAutoRetries: 1 #最大重試次數,當Eureka中可以找到服務,但是服務連不上時將會重試
MaxAutoRetriesNextServer: 1 #切換實例的重試次數
OkToRetryOnAllOperations: false # 對所有的操作請求都進行重試,如果是get則可以,如果是post,put等操作沒有實現冪等的情況下是很危險的,所以設置為false
ConnectTimeout: 1000 #請求連接的超時時間
ReadTimeout: 1800 #請求處理的超時時間

hystrix:

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

Ribbon超時與Hystrix超時問題,為了確保Ribbon重試的時候不被熔斷,我們就需要讓Hystrix的超時時間大于Ribbon的超時時間,否則Hystrix命令超時后,該命令直接熔斷,重試機制就沒有任何意義了。

從上面的配置來說,ribbon超時配置為1800,請求超時后,該實例會重試1次,更新實例會重試1次。

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

Ribbon超時與Hystrix超時問題,為了確保Ribbon重試的時候不被熔斷,我們就需要讓Hystrix的超時時間大于Ribbon的超時時間,否則Hystrix命令超時后,該命令直接熔斷,重試機制就沒有任何意義了。

補充知識:Spring Cloud Feign 第一次調用超時(Read timed out)的解決辦法

feign-client在第一次調用微服務會出現Read timed out異常,提示的報錯信息:

java.net.SocketTimeoutException: Read timed out

這是由于在調用其他微服務接口前,會去請求該微服務的相關信息(地址、端口等),并做一些初始化操作,由于默認的懶加載特性,導致了在第一次調用時,出現超時的情況,解決方法主要有兩種:

第一種辦法是設置超時時間,具體設置成多少,因項目而異,配置如下:

# 全局關閉Hystrix超時,對所有微服務有效
hystrix.command.default.execution.timeout.enabled: false

# 關閉某一個微服務的超時
hystrix.command.<serviceName>.execution.timeout.enabled: false

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

# 設置某一個微服務的超時時間為60秒
hystrix.command.<serviceName>.execution.isolation.thread.timeoutInMilliseconds: 60000

# 設置ribbon超時時間
ribbon:
ReadTimeout: 20000
ConnectTimeout: 20000

第二種辦法,也是比較推薦的方式,配置ribbon立即加載,此處需要注意的是,光配置立即加載是不生效的,還要配置客戶端列表,配置如下,詳細配置請點擊

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

最后附上未開啟立即加載時,第一次調用打印的日志:

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超時配置和hystrix的超時配置說明就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

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

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

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

    SpringBoot整合EasyExcel實現文件導入導出

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

    spring?batch線上異常定位記錄

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

    淺談junit4單元測試高級用法

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

    Spring MVC參數校驗詳解(關于`@RequestBody`返回`400`)

    這篇文章主要介紹了Spring MVC參數校驗的相關資料,主要是針對`@RequestBody`返回`400`的問題,文中通過示例代碼介紹的非常詳細,對大家具有一定的參考學習價值,需要的朋友們下面跟著小編來一起學習學習吧。
    2017-08-08
  • JAVA獲取特定格式時間方式

    JAVA獲取特定格式時間方式

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

    簡介Java編程中的Object類

    這篇文章主要介紹了簡介Java編程中的Object類,是Java入門學習中的基礎知識,需要的朋友可以參考下
    2015-09-09
  • Java Map 按key排序和按Value排序的實現方法

    Java Map 按key排序和按Value排序的實現方法

    下面小編就為大家?guī)硪黄狫ava Map 按key排序和按Value排序的實現方法。小編覺得挺不錯的,現在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-08-08
  • Java如何通過反射獲取Constructor、Field、Method對象

    Java如何通過反射獲取Constructor、Field、Method對象

    反射指的是對象的反向處理操作,根據對象取得對象的來源信息,在反射的世界里面,看重的不再是一個對象,而是對象身后的組成,下面這篇文章主要給大家介紹了關于Java如何通過反射獲取Constructor、Field、Method對象的相關資料,需要的朋友可以參考下
    2022-06-06
  • java中UDP簡單聊天程序實例代碼

    java中UDP簡單聊天程序實例代碼

    這篇文章主要介紹了java中UDP簡單聊天程序實例代碼,有需要的朋友可以參考一下
    2013-12-12

最新評論