在Spring-Boot应用程序中使用application.yaml配置hystrix命令属性

时间:2015-07-03 17:16:34

标签: spring-boot spring-cloud hystrix

我遇到同样的问题,我试图覆盖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

这是我在浏览网址时看到的 - localhost:port / app-context / hystrix.stream [这是用于hystrix仪表板的相同流网址] -

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命令& collapser属性,正确设置了线程池属性。我在 @configuration 类 -

中有以下注释
@EnableAutoConfiguration(exclude=MongoAutoConfiguration.class)
@EnableHystrix
@EnableHystrixDashboard

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

1 个答案:

答案 0 :(得分:21)

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

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

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

hystrix.threadpool.HystrixThreadPoolKey.coreSize

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

以下是我如何定义commandKey和amp; threadPoolKey由HystrixCommand包装的方法 -

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