Search in sources :

Example 1 with SentinelFlowRule

use of com.github.howinfun.sentinel.pojo.SentinelFlowRule 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)

Example 2 with SentinelFlowRule

use of com.github.howinfun.sentinel.pojo.SentinelFlowRule in project study-by-myself by Howinfun.

the class SentinelRulesGenerateConfig method onApplicationEvent.

@Override
public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
    SentinelRulesProperties sentinelRulesProperties = this.applicationContext.getBean(SentinelRulesProperties.class);
    List<SentinelFlowRule> flowRuleList = sentinelRulesProperties.getFlowRuleList();
    List<SentinelDegradeRule> degradeRuleList = sentinelRulesProperties.getDegradeRuleList();
    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 : SentinelDegradeRule(com.github.howinfun.sentinel.pojo.SentinelDegradeRule) SentinelRulesProperties(com.github.howinfun.sentinel.properties.SentinelRulesProperties) ArrayList(java.util.ArrayList) SentinelFlowRule(com.github.howinfun.sentinel.pojo.SentinelFlowRule) FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule) SentinelFlowRule(com.github.howinfun.sentinel.pojo.SentinelFlowRule) DegradeRule(com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule) SentinelDegradeRule(com.github.howinfun.sentinel.pojo.SentinelDegradeRule)

Aggregations

DegradeRule (com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule)2 FlowRule (com.alibaba.csp.sentinel.slots.block.flow.FlowRule)2 SentinelDegradeRule (com.github.howinfun.sentinel.pojo.SentinelDegradeRule)2 SentinelFlowRule (com.github.howinfun.sentinel.pojo.SentinelFlowRule)2 ArrayList (java.util.ArrayList)2 SentinelRulesProperties (com.github.howinfun.sentinel.properties.SentinelRulesProperties)1