Spring Cloud Zuul的重試配置詳解
Spring Cloud Zuul模塊本身就包含了對(duì)于hystrix和ribbon的依賴,當(dāng)我們使用zuul通過(guò)path和serviceId的組合來(lái)配置路由的時(shí)候,可以通過(guò)hystrix和ribbon的配置調(diào)整路由請(qǐng)求的各種時(shí)間超時(shí)機(jī)制。
1 ribbon配置舉例
配置連接超時(shí)時(shí)間1秒,請(qǐng)求處理時(shí)間2秒,統(tǒng)一服務(wù)server嘗試重連1次,切換server重連1次
ribbon: ConnectTimeout: 1000 ReadTimeout: 2000 MaxAutoRetries: 1 MaxAutoRetriesNextServer: 1
2 hystirx配置舉例
hystrix: command: default: execution: isolation: thread: timeoutInMilliseconds: 60000
這里需要注意的是hystrix的配置時(shí)間應(yīng)該大于ribbon全部重試時(shí)間的總和,上面我配置的是2次重試,包括首次請(qǐng)求,三次時(shí)間是6秒
引用官方大神的一段說(shuō)明
When using Hystrix commands that wrap Ribbon clients you want to make sure your Hystrix timeout is configured to be longer than the configured Ribbon timeout, including any potential
retries that might be made. For example, if your Ribbon connection timeout is one second and
the Ribbon client might retry the request three times, than your Hystrix timeout should
be slightly more than three seconds.
3 打開zuul的重試配置:
zuul: retryable: true
特別注意zuul的重試配置需要依賴spring的retry,不然的話怎么配置都是徒勞
<dependency> <groupId>org.springframework.retry</groupId> <artifactId>spring-retry</artifactId> </dependency>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Springboot多數(shù)據(jù)源配置之整合dynamic-datasource方式
這篇文章主要介紹了Springboot多數(shù)據(jù)源配置之整合dynamic-datasource方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-03-03java objectUtils 使用可能會(huì)出現(xiàn)的問題
這篇文章主要介紹了java objectUtils 使用可能會(huì)出現(xiàn)的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-02-02解決StringBuffer和StringBuilder的擴(kuò)容問題
這篇文章主要介紹了解決StringBuffer和StringBuilder的擴(kuò)容問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-07-07Java安全框架——Shiro的使用詳解(附springboot整合Shiro的demo)
這篇文章主要介紹了Java安全框架——Shiro的使用詳解,幫助大家更好的理解和學(xué)習(xí)使用Shiro,感興趣的朋友可以了解下2021-04-04SpringBoot3實(shí)現(xiàn)統(tǒng)一結(jié)果封裝的示例代碼
Spring Boot進(jìn)行統(tǒng)一結(jié)果封裝的主要目的是提高開發(fā)效率、降低代碼重復(fù)率,并且提供一致的API響應(yīng)格式,從而簡(jiǎn)化前后端交互和錯(cuò)誤處理,所以本文給大家介紹了SpringBoot3實(shí)現(xiàn)統(tǒng)一結(jié)果封裝的方法,需要的朋友可以參考下2024-03-03