【问题标题】:Configuring hystrix command properties using application.yaml in Spring-Boot application在 Spring-Boot 应用程序中使用 application.yaml 配置 hystrix 命令属性
【发布时间】:2015-09-21 14:00:01
【问题描述】:

我有同样的问题,我试图覆盖 application.yaml 中的 hystrix 属性。当我运行应用程序并使用 localhost:port/app-context/hystrix.stream 检查属性时,我得到了所有默认值。

这是我的 application.yaml 中的 hystrix 配置

hystrix:
   command.StoreSubmission.execution.isolation.thread.timeoutInMilliseconds: 30000
   command.StoreSubmission.circuitBreaker.requestVolumeThreshold: 4
   command.StoreSubmission.circuitBreaker.sleepWindowInMilliseconds: 60000
   command.StoreSubmission.metrics.rollingStats.timeInMilliseconds: 180000
   collapser.StoreSubmission.maxRequestsInBatch: 1
   collapser.StoreSubmission.requestCache.enabled: FALSE
   threadpool.StoreSubmission.coreSize: 30
   threadpool.StoreSubmission.metrics.rollingStats.timeInMilliseconds: 180000

这是我在点击 url 时看到的内容 - 浏览器中的 localhost:port/app-context/hystrix.stream [这与 hystrix 仪表板使用的流 url 相同] -

data: {"type":"HystrixCommand","name":"storeSubmission","group":"StoreSubmission","currentTime":1435941064801,"isCircuitBreakerOpen":false,"errorPercentage":0,"errorCount":0,"requestCount":0,"rollingCountCollapsedRequests":0,"rollingCountExceptionsThrown":0,"rollingCountFailure":0,"rollingCountFallbackFailure":0,"rollingCountFallbackRejection":0,"rollingCountFallbackSuccess":0,"rollingCountResponsesFromCache":0,"rollingCountSemaphoreRejected":0,"rollingCountShortCircuited":0,"rollingCountSuccess":0,"rollingCountThreadPoolRejected":0,"rollingCountTimeout":0,"currentConcurrentExecutionCount":0,"latencyExecute_mean":0,"latencyExecute":{"0":0,"25":0,"50":0,"75":0,"90":0,"95":0,"99":0,"99.5":0,"100":0},"latencyTotal_mean":0,"latencyTotal":{"0":0,"25":0,"50":0,"75":0,"90":0,"95":0,"99":0,"99.5":0,"100":0},"propertyValue_circuitBreakerRequestVolumeThreshold":20,"propertyValue_circuitBreakerSleepWindowInMilliseconds":5000,"propertyValue_circuitBreakerErrorThresholdPercentage":50,"propertyValue_circuitBreakerForceOpen":false,"propertyValue_circuitBreakerForceClosed":false,"propertyValue_circuitBreakerEnabled":true,"propertyValue_executionIsolationStrategy":"THREAD","propertyValue_executionIsolationThreadTimeoutInMilliseconds":1000,"propertyValue_executionIsolationThreadInterruptOnTimeout":true,"propertyValue_executionIsolationThreadPoolKeyOverride":null,"propertyValue_executionIsolationSemaphoreMaxConcurrentRequests":10,"propertyValue_fallbackIsolationSemaphoreMaxConcurrentRequests":10,"propertyValue_metricsRollingStatisticalWindowInMilliseconds":10000,"propertyValue_requestCacheEnabled":true,"propertyValue_requestLogEnabled":true,"reportingHosts":1}

data: {"type":"HystrixThreadPool","name":"StoreSubmission","currentTime":1435941064801,"currentActiveCount":0,"currentCompletedTaskCount":35,"currentCorePoolSize":30,"currentLargestPoolSize":30,"currentMaximumPoolSize":30,"currentPoolSize":30,"currentQueueSize":0,"currentTaskCount":35,"rollingCountThreadsExecuted":0,"rollingMaxActiveThreads":0,"propertyValue_queueSizeRejectionThreshold":5,"propertyValue_metricsRollingStatisticalWindowInMilliseconds":180000,"reportingHosts":1}

问题在于 hystrix 命令和折叠器属性,其中线程池属性设置正确。我的 @configuration 类中有以下注释 -

@EnableAutoConfiguration(exclude=MongoAutoConfiguration.class)
@EnableHystrix
@EnableHystrixDashboard

有人尝试在他们的 Spring-Boot 应用程序中使用 application.yaml 配置 hystrix 命令属性,可以帮忙吗?

【问题讨论】:

  • 我正在查看这个并注意到来自 HystrixCommand 数据的名称是小写的,而您的配置是大写的。
  • 我将您的值粘贴到我的application.yml 中,这些值通过了。
  • @spencergibb: 1. HystrixCommand 数据中传入的名称是由 HystrixCommand 包装的方法名称。 2.在配置中它的groupKey值,实际上这应该是commandKey值。 3. 当你说这些价值观出现时,在哪里出现?
  • 我现在也在努力解决这个问题,我想我离解决方案越来越近了。一旦我测试并知道它有效,将发布解决方案。
  • 这些值来自 hystrix.stream。

标签: spring-boot spring-cloud hystrix


【解决方案1】:

主要问题是,我使用 groupKey 值而不是 commandKey 值来定义属性。这些配置属性的 wiki 页面 - https://github.com/Netflix/Hystrix/wiki/Configuration#intro 说 -

hystrix.command.HystrixCommandKey.execution.isolation.thread.timeoutInMilliseconds

将属性的 HystrixCommandKey 部分替换为您为 commandkey 设置的值。

hystrix.threadpool.HystrixThreadPoolKey.coreSize

将属性的 HystrixThreadPoolKey 部分替换为您为 threadPoolKey 设置的值。

这是我如何在 HystrixCommand 包装的方法上定义 commandKey 和 threadPoolKey -

@HystrixCommand(groupKey = "StoreSubmission", commandKey = "StoreSubmission", threadPoolKey = "StoreSubmission")
public String storeSubmission(ReturnType returnType, InputStream is, String id) {
}

您实际上可以在 @HystixCommand 注释中的方法上定义命令和线程池属性。

@HystrixCommand(groupKey = "StoreSubmission", commandKey = "StoreSubmission", threadPoolKey = "StoreSubmission", commandProperties = {
        @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "30000"),
        @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "4"),
        @HystrixProperty(name = "circuitBreaker.sleepWindowInMilliseconds", value = "60000"),
        @HystrixProperty(name = "metrics.rollingStats.timeInMilliseconds", value = "180000") }, threadPoolProperties = {
        @HystrixProperty(name = "coreSize", value = "30"),
        @HystrixProperty(name = "metrics.rollingStats.timeInMilliseconds", value = "180000") })
public String storeSubmission(ReturnType returnType, InputStream is, String id) {
}

我想定义这些属性的最佳方式是在外部化的 application.yaml 中,这样您可以更好地控制它并针对不同的环境更改它们。

【讨论】:

  • 您知道如何验证这些属性是否已应用于配置 HystrixCommand 吗?反正有记录它们吗?是否可以为 Hystrix 启用 DEBUG 级别的日志记录?
  • @pijushcse 日志记录:级别:com.netflix.hystrix:'DEBUG'。第一次输入后备时,您可以看到所有值
  • 来自 spring-cloud-netflix 文档:“HystrixCommand 由名为“javanica”的 Netflix contrib 库提供。Spring Cloud 自动将带有该注释的 Spring bean 包装在连接到 Hystrix 电路的代理中断路器。断路器计算何时打开和关闭电路,以及在发生故障时该怎么做。要配置 HystrixCommand,您可以使用带有 HystrixProperty 注释列表的 commandProperties 属性。详情:github.com/Netflix/Hystrix/tree/master/hystrix-contrib/…
  • groupKey 的用途是什么?指标?
  • @wilmol:GroupKey 用于将多个 HystrixCommand 对象组合在一起,例如用于报告、警报、仪表板。
猜你喜欢
  • 2016-05-26
  • 2015-11-21
  • 2022-09-25
  • 1970-01-01
  • 2019-01-02
  • 2018-12-12
  • 2021-03-01
  • 2018-08-03
  • 2013-10-03
相关资源
最近更新 更多