use of com.alibaba.csp.sentinel.slots.block.flow.FlowRule in project JHodgepodge by werwolfGu.
the class FlowQpsDemo method initFlowQpsRule.
private static void initFlowQpsRule() {
List<FlowRule> rules = new ArrayList<FlowRule>();
FlowRule rule1 = new FlowRule();
rule1.setResource(KEY);
// set limit qps to 20
rule1.setCount(20);
rule1.setGrade(RuleConstant.FLOW_GRADE_QPS);
rule1.setLimitApp("default");
rules.add(rule1);
rule1 = new FlowRule();
rule1.setResource(KEY);
// set limit qps to 20
rule1.setCount(10);
rule1.setGrade(RuleConstant.FLOW_GRADE_QPS);
rule1.setLimitApp("caller1");
rules.add(rule1);
rule1 = new FlowRule();
rule1.setResource(KEY);
// set limit qps to 20
rule1.setCount(20);
rule1.setGrade(RuleConstant.FLOW_GRADE_QPS);
rule1.setLimitApp("caller2");
rules.add(rule1);
FlowRuleManager.loadRules(rules);
}
use of com.alibaba.csp.sentinel.slots.block.flow.FlowRule in project XHuiCloud by sindaZeng.
the class FlowRuleEntity method toRule.
@Override
public FlowRule toRule() {
FlowRule flowRule = new FlowRule();
flowRule.setCount(this.count);
flowRule.setGrade(this.grade);
flowRule.setResource(this.resource);
flowRule.setLimitApp(this.limitApp);
flowRule.setRefResource(this.refResource);
flowRule.setStrategy(this.strategy);
if (this.controlBehavior != null) {
flowRule.setControlBehavior(controlBehavior);
}
if (this.warmUpPeriodSec != null) {
flowRule.setWarmUpPeriodSec(warmUpPeriodSec);
}
if (this.maxQueueingTimeMs != null) {
flowRule.setMaxQueueingTimeMs(maxQueueingTimeMs);
}
flowRule.setClusterMode(clusterMode);
flowRule.setClusterConfig(clusterConfig);
return flowRule;
}
use of com.alibaba.csp.sentinel.slots.block.flow.FlowRule 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);
}
use of com.alibaba.csp.sentinel.slots.block.flow.FlowRule in project RuoYi-Cloud-Plus by JavaLionLi.
the class FlowRuleEntity method toRule.
@Override
public FlowRule toRule() {
FlowRule flowRule = new FlowRule();
flowRule.setCount(this.count);
flowRule.setGrade(this.grade);
flowRule.setResource(this.resource);
flowRule.setLimitApp(this.limitApp);
flowRule.setRefResource(this.refResource);
flowRule.setStrategy(this.strategy);
if (this.controlBehavior != null) {
flowRule.setControlBehavior(controlBehavior);
}
if (this.warmUpPeriodSec != null) {
flowRule.setWarmUpPeriodSec(warmUpPeriodSec);
}
if (this.maxQueueingTimeMs != null) {
flowRule.setMaxQueueingTimeMs(maxQueueingTimeMs);
}
flowRule.setClusterMode(clusterMode);
flowRule.setClusterConfig(clusterConfig);
return flowRule;
}
use of com.alibaba.csp.sentinel.slots.block.flow.FlowRule in project Sermant by huaweicloud.
the class RateLimitingRuleConverter method convertToSentinelRule.
@Override
public List<FlowRule> convertToSentinelRule(RateLimitingRule resilienceRule) {
final FlowRule flowRule = new FlowRule();
// 转换为rate/s, sentinel当前只能以1S为单位进行统计, 因此此处做一定请求比例转换
final BigDecimal divide = BigDecimal.valueOf(resilienceRule.getRate() * CommonConst.RATE_DIV_POINT).divide(BigDecimal.valueOf(resilienceRule.getParsedLimitRefreshPeriod()), RoundingMode.CEILING);
flowRule.setCount(divide.doubleValue());
flowRule.setGrade(RuleConstant.FLOW_GRADE_QPS);
flowRule.setResource(resilienceRule.getName());
return Collections.singletonList(flowRule);
}
Aggregations