查看原文
其他

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

周立 IT牧场 2021-08-10

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

Spring Cloud即将发布 SpringCloudEdgware 版本。该版本解决了不少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. zuul:

  2.  threadPool:

  3.    useSeparateThreadPools: true

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

  1. zuul:

  2.  threadPool:

  3.    useSeparateThreadPools: true

  4.    threadPoolKeyPrefix: zuulgw

相关Issue

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


    您可能也对以下帖子感兴趣

    文章有问题?点此查看未经处理的缓存