Java “无法应用”;SleepWindowIn毫秒“;Hystrix中的属性
嗨,我正在尝试在我的示例程序中使用Hystrix模式。 使用以下版本com.netflix.hystrix:hystrix核心:1.4.21Java “无法应用”;SleepWindowIn毫秒“;Hystrix中的属性,java,hystrix,circuit-breaker,Java,Hystrix,Circuit Breaker,嗨,我正在尝试在我的示例程序中使用Hystrix模式。 使用以下版本com.netflix.hystrix:hystrix核心:1.4.21 import com.netflix.hystrix.HystrixCommand; import com.netflix.hystrix.HystrixCommandGroupKey; import com.netflix.hystrix.HystrixCommandProperties; import java.util.GregorianCalen
import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.HystrixCommandProperties;
import java.util.GregorianCalendar;
import java.util.Map;
public class ServiceInvoker extends HystrixCommand<String> {
Map<String, String> serviceParams;
public String invokeService(Map<String, String> serviceParams){
System.out.println("Inside invokeService");
//Induce processing delay START
long currentTime = GregorianCalendar.getInstance().getTimeInMillis();
long timeNow = 0;
long bound = 3000;
while(timeNow < (currentTime+bound)){
timeNow = GregorianCalendar.getInstance().getTimeInMillis();
}
//Induce processing delay END
return "Service Invoked";
}
public ServiceInvoker(Map<String, String> params){
super(Setter
.withGroupKey(HystrixCommandGroupKey.Factory.asKey("MYKEY"))
.andCommandPropertiesDefaults(HystrixCommandProperties.Setter()
.withCircuitBreakerSleepWindowInMilliseconds(60000)
.withExecutionTimeoutInMilliseconds(2000)
.withCircuitBreakerErrorThresholdPercentage(5))
);
this.serviceParams=params;
}
@Override
protected String run() throws Exception {
return invokeService(serviceParams);
}
@Override
protected String getFallback() {
System.out.println("Inside FallBack");
return "FALLBACK";
}
public static void main(String args[]) throws InterruptedException {
while(true) {
ServiceInvoker si = new ServiceInvoker(null);
String op = si.execute();
System.out.println("output="+op);
Thread.sleep(100);
}
}
}
我认为,由于我已将withCircuitBreakerErrorThresholdPercentage设置为5%,并将WithCircuitBreakerSleepIndowInMouses设置为60000(1分钟),因此我认为一旦收到少量错误,它将打开电路并始终返回回退,它甚至不会尝试调用invokeService,因此不会打印“内部调用服务”60秒。
请有人解释一下,为什么电路没有被打开?还有参数
断路器。requestVolumeThreshold
默认值为20-这意味着统计窗口中总共需要至少20个请求。窗口的大小由metrics.rollingStats.timeinms
配置>
如果窗口中没有达到20个请求,断路器将不会跳闸
调查此场景时,您可能还需要记录来自
HystrixCommandMetrics
的信息。还有参数断路器。requestVolumeThreshold
默认值为20-意味着您在统计窗口中总共需要至少20个请求。窗口的大小由met配置rics.rollingStats.timeinms
如果窗口中没有达到20个请求,断路器将不会跳闸
调查此场景时,您可能还需要记录来自HystrixCommandMetrics
的信息
Inside invokeService
Inside FallBack
output=FALLBACK