web-dev-qa-db-ja.com

Spring-Bootアプリケーションでapplication.yamlを使用して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

これは、URLにアクセスしたときに表示されるものです-localhost:port/app-context/hystrix.stream in browser [これは、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

誰かがこの春ブートアプリケーションでapplication.yamlを使用してhystrixコマンドプロパティを設定しようとしましたか?

14
Amrut

主な問題は、commandKey値ではなくgroupKey値を使用してプロパティを定義していたことです。これらの構成プロパティの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を使用することだと思います。この方法で、より適切に制御し、さまざまな環境に合わせて変更できます。

23
Amrut