web-dev-qa-db-fra.com

Configuration des propriétés de la commande hystrix à l'aide de application.yaml dans l'application Spring-Boot

J'ai le même problème, où j'essaie de remplacer les propriétés hystrix dans application.yaml. Lorsque j'exécute l'application et vérifie les propriétés avec localhost: port/app-context/hystrix.stream, j'obtiens toutes les valeurs par défaut à la place.

voici la configuration hystrix dans mon 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

Voici ce que je vois lorsque j'appuie sur l'URL - localhost: port/app-context/hystrix.stream dans le navigateur [c'est la même URL de flux utilisée pour le tableau de bord 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}

Le problème vient des commandes hystrix et des propriétés de collapser, où les propriétés de pool de threads sont définies correctement. J'ai les annotations suivantes dans ma classe @ configuration -

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

Quelqu'un a-t-il essayé de configurer les propriétés de la commande hystrix en utilisant application.yaml dans leur application Spring-Boot, peut-il vous aider?

14
Amrut

Le problème principal était que j'utilisais la valeur groupKey au lieu de la valeur commandKey pour définir les propriétés. La page wiki pour ces propriétés de configuration - https://github.com/Netflix/Hystrix/wiki/Configuration#intro dit -

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

Remplacez la partie HystrixCommandKey de la propriété par la valeur que vous définissez pour commandkey.

hystrix.threadpool.HystrixThreadPoolKey.coreSize

Remplacez la partie HystrixThreadPoolKey de la propriété par la valeur que vous définissez pour threadPoolKey.

Voici comment je définis à la fois commandKey et threadPoolKey sur la méthode enveloppée par HystrixCommand -

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

Vous pouvez réellement définir les propriétés de la commande et du pool de threads sur la méthode dans l'annotation @ 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) {
}

Je suppose que la meilleure façon de définir ces propriétés est dans externalized application.yaml, de cette façon vous pouvez mieux le contrôler et les changer pour différents environnements.

23
Amrut