Search in sources :

Example 11 with DegradeRule

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);
}
Also used : ArrayList(java.util.ArrayList) DegradeRule(com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule)

Example 12 with DegradeRule

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());
}
Also used : RedissonClient(org.redisson.api.RedissonClient) List(java.util.List) FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule) DegradeRule(com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule)

Example 13 with DegradeRule

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;
}
Also used : DegradeRule(com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule)

Example 14 with DegradeRule

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);
}
Also used : ArrayList(java.util.ArrayList) DegradeRule(com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule)

Example 15 with DegradeRule

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);
}
Also used : ArrayList(java.util.ArrayList) SentinelFlowRule(com.github.howinfun.sentinel.pojo.SentinelFlowRule) FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule) SentinelDegradeRule(com.github.howinfun.sentinel.pojo.SentinelDegradeRule) DegradeRule(com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule)

Aggregations

DegradeRule (com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule)34 ArrayList (java.util.ArrayList)12 FlowRule (com.alibaba.csp.sentinel.slots.block.flow.FlowRule)9 Test (org.junit.Test)4 List (java.util.List)3 ApiDefinition (com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiDefinition)2 GatewayFlowRule (com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule)2 AuthorityRule (com.alibaba.csp.sentinel.slots.block.authority.AuthorityRule)2 ParamFlowItem (com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowItem)2 ParamFlowRule (com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule)2 SystemRule (com.alibaba.csp.sentinel.slots.system.SystemRule)2 AbstractTimeBasedTest (com.alibaba.csp.sentinel.test.AbstractTimeBasedTest)2 SentinelDegradeRule (com.github.howinfun.sentinel.pojo.SentinelDegradeRule)2 SentinelFlowRule (com.github.howinfun.sentinel.pojo.SentinelFlowRule)2 HashSet (java.util.HashSet)2 RuleData (org.apache.shenyu.common.dto.RuleData)2 SentinelHandle (org.apache.shenyu.common.dto.convert.rule.SentinelHandle)2 EntryType (com.alibaba.csp.sentinel.EntryType)1 DegradeRuleManager (com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager)1 FlowRuleManager (com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager)1