Fork me on GitHub

Spring Cloud Edgware新特性之二:如何配置Zuul的Hystrix线程池

目录

Spring Cloud是当前炙手可热的微服务开发框架。它的功能强大,组件丰富,设计优雅。目前Spring Cloud还在不断发展之中。

Spring Cloud即将发布Spring Cloud Edgware 版本。该版本解决了不少Bug,新增了不少新特性,本系列博客将为大家详细阐述在Spring Cloud Edgware中新增的特性。

本文为大家讲解如何配置Zuul的Hystrix线程池。

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线程池中执行。

可使用以下配置,让每个路由使用独立的线程池:

1
2
3
zuul:
threadPool:
useSeparateThreadPools: true

使用如上配置后,默认的HystrixThreadPoolkey 将与每个路由的服务标识相同。如果你想HystrixThreadPoolKey 添加前缀,可使用类似如下的配置:

1
2
3
4
zuul:
threadPool:
useSeparateThreadPools: true
threadPoolKeyPrefix: zuulgw

相关Issue

https://github.com/spring-cloud/spring-cloud-netflix/pull/2074

相关文章

评论系统未开启,无法评论!