use of com.alibaba.csp.sentinel.slots.block.flow.FlowRule in project Sermant by huaweicloud.
the class FlowRuleVo 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 rocketmq-externals by apache.
the class PullConsumerDemo method initFlowControlRule.
private static void initFlowControlRule() {
FlowRule rule = new FlowRule();
rule.setResource(KEY);
// Indicates the interval between two adjacent requests is 200 ms.
rule.setCount(5);
rule.setGrade(RuleConstant.FLOW_GRADE_QPS);
rule.setLimitApp("default");
// Enable rate limiting (uniform). This can ensure fixed intervals between two adjacent calls.
// In this example, intervals between two incoming calls (message consumption) will be 200 ms constantly.
rule.setControlBehavior(RuleConstant.CONTROL_BEHAVIOR_RATE_LIMITER);
// If more requests are coming, they'll be put into the waiting queue.
// The queue has a queueing timeout. Requests that may exceed the timeout will be immediately blocked.
// In this example, the max timeout is 5s.
rule.setMaxQueueingTimeMs(5 * 1000);
FlowRuleManager.loadRules(Collections.singletonList(rule));
}
use of com.alibaba.csp.sentinel.slots.block.flow.FlowRule in project javaBook-src by huifer.
the class FirstDemo method initFlowRules.
public static void initFlowRules(String resource) {
List<FlowRule> rules = new ArrayList<>();
FlowRule rule = new FlowRule();
rule.setResource(resource);
// 限流阈值类型,此处为qps类型
rule.setGrade(RuleConstant.FLOW_GRADE_QPS);
// 限流阈值,表示每秒钟通过5次请求
rule.setCount(5);
rules.add(rule);
FlowRuleManager.loadRules(rules);
}
use of com.alibaba.csp.sentinel.slots.block.flow.FlowRule in project spring-cloud-alibaba by alibaba.
the class SentinelAutoConfigurationTests method setUp.
@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));
}
use of com.alibaba.csp.sentinel.slots.block.flow.FlowRule in project spring-cloud-alibaba by alibaba.
the class SentinelFeignTests method setUp.
@Before
public void setUp() {
FlowRule rule1 = new FlowRule();
rule1.setGrade(RuleConstant.FLOW_GRADE_QPS);
rule1.setCount(0);
rule1.setResource("GET:http://test-service/echo/{str}");
rule1.setLimitApp("default");
rule1.setControlBehavior(RuleConstant.CONTROL_BEHAVIOR_DEFAULT);
rule1.setStrategy(RuleConstant.STRATEGY_DIRECT);
FlowRule rule2 = new FlowRule();
rule2.setGrade(RuleConstant.FLOW_GRADE_QPS);
rule2.setCount(0);
rule2.setResource("GET:http://foo-service/echo/{str}");
rule2.setLimitApp("default");
rule2.setControlBehavior(RuleConstant.CONTROL_BEHAVIOR_DEFAULT);
rule2.setStrategy(RuleConstant.STRATEGY_DIRECT);
FlowRule rule3 = new FlowRule();
rule3.setGrade(RuleConstant.FLOW_GRADE_QPS);
rule3.setCount(0);
rule3.setResource("GET:http://bar-service/bar");
rule3.setLimitApp("default");
rule3.setControlBehavior(RuleConstant.CONTROL_BEHAVIOR_DEFAULT);
rule3.setStrategy(RuleConstant.STRATEGY_DIRECT);
FlowRule rule4 = new FlowRule();
rule4.setGrade(RuleConstant.FLOW_GRADE_QPS);
rule4.setCount(0);
rule4.setResource("GET:http://baz-service/baz");
rule4.setLimitApp("default");
rule4.setControlBehavior(RuleConstant.CONTROL_BEHAVIOR_DEFAULT);
rule4.setStrategy(RuleConstant.STRATEGY_DIRECT);
FlowRuleManager.loadRules(Arrays.asList(rule1, rule2, rule3, rule4));
}
Aggregations