在 Spring-Boot 应用程序中使用 application.yaml 配置 hystrix 命令属性 [英] Configuring hystrix command properties using application.yaml in Spring-Boot application

查看:31
本文介绍了在 Spring-Boot 应用程序中使用 application.yaml 配置 hystrix 命令属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am having same issue, where i am trying to override the hystrix properties in application.yaml. When I run the app & check the properties with localhost:port/app-context/hystrix.stream, I get all default values instead.

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

here is the hystrix config in my application.yaml

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 相同] -

Here is what I see when I hit the url - localhost:port/app-context/hystrix.stream in browser [ this is same stream url used for hystrix dashboard ] -

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 类中有以下注释 -

The problem is with hystrix command & collapser properties, where as threadpool properties are set correctly. I have got following annotations in my @configuration class -

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

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

Has someone tried configuring hystrix command properties using application.yaml in thier Spring-Boot application, can help please?

推荐答案

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

The main problem was that, I was using groupKey value instead of commandKey value to define the properties. The wiki page for these configuration properties - https://github.com/Netflix/Hystrix/wiki/Configuration#intro says -

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

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

Replace the HystrixCommandKey portion of the property with the value you set for commandkey.

hystrix.threadpool.HystrixThreadPoolKey.coreSize

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

Replace the HystrixThreadPoolKey portion of the property with the value you set for threadPoolKey.

这里是我如何定义 commandKey &通过HystrixCommand封装的方法的threadPoolKey -

Here is how I define both commandKey & threadPoolKey over the method wrapped by HystrixCommand -

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

您实际上可以同时定义 command &@HystixCommand 注释中方法的线程池属性.

You can actually define both command & threadpool properties on the method within @HystixCommand annotation.

@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 中,这样你就可以更好地控制它&为不同的环境更改它们.

I guess the best way to define these properties is in externalized application.yaml, that way you can control it better & change them for different environments.

这篇关于在 Spring-Boot 应用程序中使用 application.yaml 配置 hystrix 命令属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆