猬属性也可以在里面 @HystrixCommand注解我们的服务类设置,为此我们使用Hystrix-Javanica 项目,该项目用于我们的项目实施的注释。 为此,我们需要将hystrix-javanica的依赖关系添加到我们的 类路径中。
依赖Maven的:
<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-javanica</artifactId>
<version>x.y.z</version>
</dependency>
里面的@HystrixCommand注解我们可以用@HystrixProperty为椎设置的属性。
样品@HystrixCommand属性设置:
@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,这样你可以控制它更好&改变他们对不同的环境。
这里是我的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
为application.yml文件的具体格式是
hystrix:
command:
findAllProducts:
execution:
isolation:
thread:
timeoutInMilliseconds: 1000
circuitBreaker:
requestVolumeThreshold: 20
errorThresholdPercentage: 50
metrics:
rollingStats:
timeInMilliseconds: 10000
numBuckets: 10
threadpool:
ProductService:
coreSize: 10
有关豪猪,鸦胆子访问进一步信息here
我面临着类似的问题 - 一旦我在某个组中创建了第一个带有Setter的HystrixCommand,之后我无法通过创建一个具有不同Setter的新HystrixCommand来更改属性(在同一组中)。那么hystrix是如何从它获得的第一个Setter中“缓存”属性的情况的确如此,除了使用ConfigurationManager之外,真的没有办法改变属性吗? –