Hystrix Configuration in Properties file
1 min readDec 16, 2019
We use netflix hystrix circuit breaker our microservices. We use hystrix annotation like this:
@HystrixCommand(fallbackMethod = "getEmptyResult",
threadPoolKey = "getProductThreadPool",
commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "50"),
@HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "10"),
@HystrixProperty(name = "circuitBreaker.sleepWindowInMilliseconds", value = "1000"),
@HystrixProperty(name = "circuitBreaker.errorThresholdPercentage", value = "10"),
@HystrixProperty(name = "execution.isolation.strategy", value = "THREAD"),
@HystrixProperty(name = "metrics.rollingStats.timeInMilliseconds", value = "20000"),
@HystrixProperty(name = "metrics.rollingPercentile.timeInMilliseconds", value = "20000"),
@HystrixProperty(name = "metrics.healthSnapshot.intervalInMilliseconds", value = "5000"),
@HystrixProperty(name = "fallback.isolation.semaphore.maxConcurrentRequests", value = "100")
},
threadPoolProperties = {
@HystrixProperty(name = "coreSize", value = "30"),
@HystrixProperty(name = "maxQueueSize", value = "-1"),
}
)
@Override
public ProductDto getProduct(Integer productId) {
... call other microservices
}
private ProductDto getEmptyResult(Integer productId, Throwable error) {
logger.warn("logFor=CircuitBreaker productId={}, method={}, exception={}", productId,
"getProduct", error);
return null;
}
So I want to move this config our configuration files. I search how can I do it so I check hystrix documentation page https://github.com/Netflix/Hystrix/wiki/Configuration#command-properties
There is command properties tag we can easy to use properties file hystrix configuration.
We can do like this;
hystrix.command.{commandKey}.{propertiesName}=value
OR
hystrix.command.default.{propertiesName}=value
If properties not found commendKey hystrix use default config.
For example
hystrix.commeand.productCommandKey.execution.isolation.thread.timeoutInMilliseconds=50
hystrix.commeand.default.circuitBreaker.requestVolumeThreshold=10
Change the annotation properties. We use threadPoolKey and commandKey properties file
@HystrixCommand(fallbackMethod = "getEmptyResult",
threadPoolKey = "getProductThreadPool",
commandKey = "getProductServiceCommand"
)
@Override
public ProductDto getProduct(Integer productId) {
... call other microservices
}
private ProductDto getEmptyResult(Integer productId, Throwable error) {
logger.warn("logFor=CircuitBreaker productId={}, method={}, exception={}", productId,
"getProduct", error);
return null;
}
Add the properties file this configs
hystrix.command.getProductServiceCommand.execution.isolation.thread.timeoutInMilliseconds=50
hystrix.command.getProductServiceCommand.circuitBreaker.requestVolumeThreshold=10
hystrix.command.getProductServiceCommand.circuitBreaker.sleepWindowInMilliseconds=1000
hystrix.command.getProductServiceCommand.circuitBreaker.errorThresholdPercentage=10
hystrix.command.getProductServiceCommand.execution.isolation.strategy=THREAD
hystrix.command.getProductServiceCommand.metrics.rollingStats.timeInMilliseconds=20000
hystrix.command.getProductServiceCommand.metrics.rollingPercentile.timeInMilliseconds=20000
hystrix.command.getProductServiceCommand.metrics.healthSnapshot.intervalInMilliseconds=5000
hystrix.command.getProductServiceCommand.fallback.isolation.semaphore.maxConcurrentRequests=100hystrix.threadpool.getProductServiceThreadPool.coreSize=30
hystrix.threadpool.getProductServiceThreadPool.maxQueueSize=-1