Java Code Examples for com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule#setResource()
The following examples show how to use
com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule#setResource() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExceptionCountDegradeDemo.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 6 votes |
private static void initDegradeRule() { List<DegradeRule> rules = new ArrayList<DegradeRule>(); DegradeRule rule = new DegradeRule(); rule.setResource(KEY); // set limit exception count to 4 rule.setCount(4); rule.setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT); /** * When degrading by {@link RuleConstant#DEGRADE_GRADE_EXCEPTION_COUNT}, time window * less than 60 seconds will not work as expected. Because the exception count is * summed by minute, when a short time window elapsed, the degradation condition * may still be satisfied. */ rule.setTimeWindow(10); rules.add(rule); DegradeRuleManager.loadRules(rules); }
Example 2
Source File: ExceptionCountDegradeDemo.java From Sentinel with Apache License 2.0 | 6 votes |
private static void initDegradeRule() { List<DegradeRule> rules = new ArrayList<DegradeRule>(); DegradeRule rule = new DegradeRule(); rule.setResource(KEY); // set limit exception count to 4 rule.setCount(4); rule.setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT); /** * When degrading by {@link RuleConstant#DEGRADE_GRADE_EXCEPTION_COUNT}, time window * less than 60 seconds will not work as expected. Because the exception count is * summed by minute, when a short time window elapsed, the degradation condition * may still be satisfied. */ rule.setTimeWindow(10); rules.add(rule); DegradeRuleManager.loadRules(rules); }
Example 3
Source File: SentinelAutoConfigurationTests.java From spring-cloud-alibaba with Apache License 2.0 | 6 votes |
@Before public void setUp() { FlowRule rule = new FlowRule(); rule.setGrade(RuleConstant.FLOW_GRADE_QPS); rule.setCount(0); rule.setResource("GET:" + flowUrl); rule.setLimitApp("default"); rule.setControlBehavior(RuleConstant.CONTROL_BEHAVIOR_DEFAULT); rule.setStrategy(RuleConstant.STRATEGY_DIRECT); FlowRuleManager.loadRules(Arrays.asList(rule)); DegradeRule degradeRule = new DegradeRule(); degradeRule.setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT); degradeRule.setResource("GET:" + degradeUrl); degradeRule.setCount(0); degradeRule.setTimeWindow(60); DegradeRuleManager.loadRules(Arrays.asList(degradeRule)); }
Example 4
Source File: ExceptionRatioDegradeDemo.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 5 votes |
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); }
Example 5
Source File: RtDegradeDemo.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 5 votes |
private static void initDegradeRule() { List<DegradeRule> rules = new ArrayList<DegradeRule>(); DegradeRule rule = new DegradeRule(); rule.setResource(KEY); // set threshold rt, 10 ms rule.setCount(10); rule.setGrade(RuleConstant.DEGRADE_GRADE_RT); rule.setTimeWindow(10); rules.add(rule); DegradeRuleManager.loadRules(rules); }
Example 6
Source File: DegradeRuleEntity.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 5 votes |
@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; }
Example 7
Source File: ExceptionRatioDegradeDemo.java From Sentinel with Apache License 2.0 | 5 votes |
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); }
Example 8
Source File: RtDegradeDemo.java From Sentinel with Apache License 2.0 | 5 votes |
private static void initDegradeRule() { List<DegradeRule> rules = new ArrayList<DegradeRule>(); DegradeRule rule = new DegradeRule(); rule.setResource(KEY); // set threshold rt, 10 ms rule.setCount(10); rule.setGrade(RuleConstant.DEGRADE_GRADE_RT); rule.setTimeWindow(10); rules.add(rule); DegradeRuleManager.loadRules(rules); }
Example 9
Source File: DegradeRuleEntity.java From Sentinel with Apache License 2.0 | 5 votes |
@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; }
Example 10
Source File: SentinelCircuitBreaker.java From spring-cloud-alibaba with Apache License 2.0 | 5 votes |
private void applyToSentinelRuleManager() { if (this.rules == null || this.rules.isEmpty()) { return; } Set<DegradeRule> ruleSet = new HashSet<>(DegradeRuleManager.getRules()); for (DegradeRule rule : this.rules) { if (rule == null) { continue; } rule.setResource(resourceName); ruleSet.add(rule); } DegradeRuleManager.loadRules(new ArrayList<>(ruleSet)); }
Example 11
Source File: ReactiveSentinelCircuitBreaker.java From spring-cloud-alibaba with Apache License 2.0 | 5 votes |
private void applyToSentinelRuleManager() { if (this.rules == null || this.rules.isEmpty()) { return; } Set<DegradeRule> ruleSet = new HashSet<>(DegradeRuleManager.getRules()); for (DegradeRule rule : this.rules) { if (rule == null) { continue; } rule.setResource(resourceName); ruleSet.add(rule); } DegradeRuleManager.loadRules(new ArrayList<>(ruleSet)); }