Java Code Examples for com.alibaba.csp.sentinel.slots.block.flow.FlowRule#setStrategy()

The following examples show how to use com.alibaba.csp.sentinel.slots.block.flow.FlowRule#setStrategy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FlowRuleEntity.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 2
Source File: UserService.java    From sentinel-tutorial with Apache License 2.0 6 votes vote down vote up
public UserService(){
    // 定义热点限流的规则,对第一个参数设置 qps 限流模式,阈值为5
    FlowRule rule = new FlowRule();
    rule.setResource(USER_RES);
    // 限流类型,qps
    rule.setGrade(RuleConstant.FLOW_GRADE_QPS);
    // 设置阈值
    rule.setCount(5);
    // 限制哪个调用方
    rule.setLimitApp(RuleConstant.LIMIT_APP_DEFAULT);
    // 基于调用关系的流量控制
    rule.setStrategy(RuleConstant.STRATEGY_DIRECT);
    // 流控策略
    rule.setControlBehavior(RuleConstant.CONTROL_BEHAVIOR_DEFAULT);
    FlowRuleManager.loadRules(Collections.singletonList(rule));
}
 
Example 3
Source File: FlowRuleEntity.java    From Sentinel with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 4
Source File: SentinelAutoConfigurationTests.java    From spring-cloud-alibaba with Apache License 2.0 6 votes vote down vote up
@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));

	DegradeRule degradeRule = new DegradeRule();
	degradeRule.setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT);
	degradeRule.setResource("GET:" + degradeUrl);
	degradeRule.setCount(0);
	degradeRule.setTimeWindow(60);
	DegradeRuleManager.loadRules(Arrays.asList(degradeRule));
}
 
Example 5
Source File: SentinelFeignTests.java    From spring-cloud-alibaba with Apache License 2.0 5 votes vote down vote up
@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));
}