use of com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule in project JHodgepodge by werwolfGu.
the class ExceptionRatioDegradeDemo method initDegradeRule.
private static void initDegradeRule() {
List<DegradeRule> rules = new ArrayList<DegradeRule>();
DegradeRule rule = new DegradeRule();
rule.setResource(KEY);
// set limit exception ratio to 0.1
rule.setCount(0.1);
rule.setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION_RATIO);
rule.setTimeWindow(10);
rule.setMinRequestAmount(20);
rules.add(rule);
DegradeRuleManager.loadRules(rules);
}
use of com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule in project JHodgepodge by werwolfGu.
the class SentinelDemo method main.
public static void main(String[] args) {
Converter<String, List<FlowRule>> flowConfigParser = buildFlowConfigParser();
RedissonClient redissonClient = null;
String ruleKey = "flowRule:${appid}";
String channel = "flow:topic:${appid}";
ReadableDataSource<String, List<FlowRule>> redisDataSource = new RedisDataSource<List<FlowRule>>(redissonClient, ruleKey, channel, flowConfigParser) {
@Override
public String defaultReadSrouce() {
return null;
}
};
FlowRuleManager.register2Property(redisDataSource.getProperty());
String degradeKey = "degradeRule:${appid}";
String degradeTopic = "degrade:topic:${appid}";
ReadableDataSource<String, List<DegradeRule>> redisDegradeRule = new RedisDataSource<List<DegradeRule>>(redissonClient, degradeKey, degradeTopic, buildFDegradeConfigParser()) {
@Override
public String defaultReadSrouce() {
return null;
}
};
DegradeRuleManager.register2Property(redisDegradeRule.getProperty());
}
use of com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule in project XHuiCloud by sindaZeng.
the class DegradeRuleEntity method toRule.
@Override
public DegradeRule toRule() {
DegradeRule rule = new DegradeRule();
rule.setResource(resource);
rule.setLimitApp(limitApp);
rule.setCount(count);
rule.setTimeWindow(timeWindow);
rule.setGrade(grade);
return rule;
}
use of com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule in project study-by-myself by Howinfun.
the class ExceptionRatioCircuitBreakerDemo method initDegradeRule.
private static void initDegradeRule() {
List<DegradeRule> rules = new ArrayList<>();
DegradeRule rule = new DegradeRule(KEY).setGrade(CircuitBreakerStrategy.ERROR_RATIO.getType()).setCount(0.5d).setStatIntervalMs(30000).setMinRequestAmount(50).setTimeWindow(10);
rules.add(rule);
DegradeRuleManager.loadRules(rules);
System.out.println("Degrade rule loaded: " + rules);
}
use of com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule in project study-by-myself by Howinfun.
the class AbstractSentinelRulesListener method reloadSentinelRules.
public void reloadSentinelRules(List<SentinelFlowRule> flowRuleList, List<SentinelDegradeRule> degradeRuleList) {
final List<FlowRule> flowRules = new ArrayList<>();
final List<DegradeRule> degradeRules = new ArrayList<>();
// 处理流控规则
flowRuleList.forEach(sentinelFlowRule -> {
FlowRule flowRule = new FlowRule();
BeanUtils.copyProperties(sentinelFlowRule, flowRule);
flowRules.add(flowRule);
});
// 处理熔断规则
degradeRuleList.forEach(sentinelDegradeRule -> {
DegradeRule degradeRule = new DegradeRule();
BeanUtils.copyProperties(sentinelDegradeRule, degradeRule);
degradeRules.add(degradeRule);
});
FlowRuleManager.loadRules(flowRules);
DegradeRuleManager.loadRules(degradeRules);
}
Aggregations