如何解决Hystrix:为什么rollingStats.timeInMilliseconds 没有生效?
这是我做过的实验设置: rollingStats.timeInMilliseconds: 100 sleepWindowInMilliseconds: 200000 错误阈值百分比:20 请求量阈值:1
我的目的是创建一个场景,在 1 次失败后,它将立即进入 sleep window ,因此除非 200 秒结束,否则它不会执行 run。但是我看到的是,它在第一次失败后尝试了 3 秒以上,这意味着它一直在调用 run 方法。我一定是错了。请给我一些指导。
package com.test.mock;
import com.netflix.config.ConfigurationManager;
import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.HystrixCommandProperties.ExecutionIsolationStrategy;
import com.netflix.hystrix.strategy.concurrency.HystrixRequestContext;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
public class HystrixDemoCommand extends HystrixCommand<String> {
public HystrixDemoCommand() throws Exception {
super(HystrixCommandGroupKey.Factory.asKey("HystrixDemoCommandGroup"));
HystrixCommandGroupKey.Factory.asKey("HystrixDemoCommandGroup");
try {
ConfigurationManager.getConfigInstance().setProperty("hystrix.command.HystrixDemoCommandGroup.execution.isolation.strategy",ExecutionIsolationStrategy.SEMAPHORE);
ConfigurationManager.getConfigInstance().setProperty("hystrix.command.HystrixDemoCommandGroup.metrics.rollingStats.timeInMilliseconds",100);
ConfigurationManager.getConfigInstance().setProperty("hystrix.command.HystrixDemoCommandGroup.circuitBreaker.sleepWindowInMilliseconds",200000);
ConfigurationManager.getConfigInstance().setProperty("hystrix.command.HystrixDemoCommandGroup.circuitBreaker.errorThresholdPercentage",20);
ConfigurationManager.getConfigInstance().setProperty("hystrix.command.HystrixDemoCommandGroup.circuitBreaker.requestVolumeThreshold",1);
} catch (Exception exception) {
throw new Exception("error initializing hystrix");
}
}
@Override
protected String run() throws Exception {
/**client code starts here**/
System.out.println("planning to execute run");
Client client = Client.create();
WebResource webresource = client.resource("https://a73c392-510a-4df3-9898-6e18dd2f773c.mock.pstmn.io/mockName");
String responseStr = webresource.get(String.class);
System.out.println("printing response:" + responseStr);
return responseStr;
/**client code ends here**/
}
protected String getFallback(){
System.out.println("inside fallback");
return "FALLBACK_0001";
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。