Configuring hystrix command properties using application.yaml in Spring-Boot application

后端 未结 1 624
走了就别回头了
走了就别回头了 2020-12-13 10:47

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-conte

相关标签:
1条回答
  • 2020-12-13 11:15

    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
    

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

    hystrix.threadpool.HystrixThreadPoolKey.coreSize
    

    Replace the HystrixThreadPoolKey portion of the property with the value you set for 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) {
    }
    

    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) {
    }
    

    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.

    0 讨论(0)
提交回复
热议问题