use of com.alibaba.csp.sentinel.slots.block.flow.FlowRule in project spring-cloud-alibaba by alibaba.
the class SentinelConverterTests method testXmlConverter.
@Test
public void testXmlConverter() {
XmlConverter jsonConverter = new XmlConverter(xmlMapper, FlowRule.class);
List<FlowRule> flowRules = (List<FlowRule>) jsonConverter.convert(readFileContent("classpath: flowrule.xml"));
assertThat(flowRules.size()).isEqualTo(2);
assertThat(flowRules.get(0).getResource()).isEqualTo("resource");
assertThat(flowRules.get(0).getLimitApp()).isEqualTo("default");
assertThat(String.valueOf(flowRules.get(0).getCount())).isEqualTo("1.0");
assertThat(flowRules.get(0).getControlBehavior()).isEqualTo(RuleConstant.CONTROL_BEHAVIOR_DEFAULT);
assertThat(flowRules.get(0).getStrategy()).isEqualTo(RuleConstant.STRATEGY_DIRECT);
assertThat(flowRules.get(0).getGrade()).isEqualTo(RuleConstant.FLOW_GRADE_QPS);
assertThat(flowRules.get(1).getResource()).isEqualTo("test");
assertThat(flowRules.get(1).getLimitApp()).isEqualTo("default");
assertThat(String.valueOf(flowRules.get(1).getCount())).isEqualTo("1.0");
assertThat(flowRules.get(1).getControlBehavior()).isEqualTo(RuleConstant.CONTROL_BEHAVIOR_DEFAULT);
assertThat(flowRules.get(1).getStrategy()).isEqualTo(RuleConstant.STRATEGY_DIRECT);
assertThat(flowRules.get(1).getGrade()).isEqualTo(RuleConstant.FLOW_GRADE_QPS);
}
use of com.alibaba.csp.sentinel.slots.block.flow.FlowRule in project solon by noear.
the class CloudBreakerEntryImpl method loadRules.
private void loadRules() {
List<FlowRule> ruleList = new ArrayList<>();
FlowRule rule = null;
rule = new FlowRule();
rule.setResource(breakerName);
// qps
rule.setGrade(RuleConstant.FLOW_GRADE_QPS);
rule.setCount(thresholdValue);
ruleList.add(rule);
rule = new FlowRule();
rule.setResource(breakerName);
// 并发数
rule.setGrade(RuleConstant.FLOW_GRADE_THREAD);
rule.setCount(thresholdValue);
ruleList.add(rule);
FlowRuleManager.loadRules(ruleList);
}
use of com.alibaba.csp.sentinel.slots.block.flow.FlowRule in project spring-boot-student by wyh-spring-ecosystem-student.
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 slate by shepherdviolet.
the class AbstractEzSentinelRuleConfigurer method commentRule.
protected static FlowRule commentRule(String comment) {
FlowRule flowRule = new FlowRule(comment);
flowRule.setCount(0);
return flowRule;
}
use of com.alibaba.csp.sentinel.slots.block.flow.FlowRule 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());
}
Aggregations