我正在编写一个应用程序,我想实现
circuit breaker模式.这是我写的Hystrix Command类:
public class HystrixCommandNextGen extends HystrixCommand {
private ScriptContext scriptctx;
private ScriptFactory scriptFactory;
private ScriptContext responseContext = null;
private Logger logger = LoggerFactory.getLogger(HystrixCommandNextGen.class);
public HystrixCommandNextGen(ScriptContext scriptctx, ScriptFactory scriptFactory) {
super(
Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("Thread_Pool"))
.andCommandKey(HystrixCommandKey.Factory.asKey(scriptctx.getExecutionData(ExecutionParam.SCRIPTNAME)))
);
this.scriptctx = scriptctx;
this.scriptFactory = scriptFactory;
HystrixCommandProperties.Setter().withCircuitBreakerEnabled(true);
HystrixCommandProperties.Setter().withCircuitBreakerRequestVolumeThreshold(150);
}
@Override
protected ScriptContext run() throws Exception {
scriptFactory.execute(scriptctx);
return scriptctx;
}
@Override
protected ScriptContext getFallback() {
logger.error("FI is not responding: Error occurred in the execution of " + getClass().getSimpleName());
return scriptctx;
}
}
我无法理解如何配置线程数,断路器的阈值时间和要处理的请求数.