Spring Cloud是當前煊赫一時的微服務開發框架。它的功能強大,組件豐富,設計優雅。目前Spring Cloud還在不斷髮展之中。git
Spring Cloud即將發佈Spring Cloud Edgware 版本。該版本解決了很多Bug,新增了很多新特性,本系列博客將爲你們詳細闡述在Spring Cloud Edgware中新增的特性。github
本文爲你們講解如何配置Zuul的Hystrix線程池。spring
TIPS微信
本文中的HystrixThreadPoolKey 跟《Hystrix配置說明( https://github.com/Netflix/Hystrix/wiki/Configuration ) 》中的HystrixThreadPoolKey 是一個東西,若是你不瞭解HystrixThreadPoolKey ,不瞭解線程隔離策略,請《詳細閱讀Hystrix配置說明》。瞭解這倆術語概念後,再閱讀本文,會事半功倍。框架
默認狀況下,Zuul的隔離策略是SEMAPHORE 。但一些場景下,咱們可能須要將隔離策略改成THREAD 設置zuul.ribbonIsolationStrategy=THREAD 便可。當 zuul.ribbonIsolationStrategy=THREAD 時,Hystrix的線程隔離策略將會做用於全部路由。微服務
此時,HystrixThreadPoolKey 默認爲「RibbonCommand」。這意味着,全部路由的HystrixCommand都會在相同的Hystrix線程池中執行。線程
可以使用如下配置,讓每一個路由使用獨立的線程池:設計
zuul: threadPool: useSeparateThreadPools: true
使用如上配置後,默認的HystrixThreadPoolkey 將與每一個路由的服務標識相同。若是你想HystrixThreadPoolKey 添加前綴,可以使用相似以下的配置:code
zuul: threadPool: useSeparateThreadPools: true threadPoolKeyPrefix: zuulgw
相關Issue路由
https://github.com/spring-cloud/spring-cloud-netflix/pull/2074