Search in sources :

Example 51 with FlowRule

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;
}
Also used : FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule)

Example 52 with 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));
}
Also used : FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule)

Example 53 with FlowRule

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);
}
Also used : ArrayList(java.util.ArrayList) FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule)

Example 54 with FlowRule

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));
}
Also used : FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule) Before(org.junit.Before)

Example 55 with FlowRule

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));
}
Also used : FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule) Before(org.junit.Before)

Aggregations

FlowRule (com.alibaba.csp.sentinel.slots.block.flow.FlowRule)113 ArrayList (java.util.ArrayList)31 Test (org.junit.Test)31 ClusterNode (com.alibaba.csp.sentinel.node.ClusterNode)22 List (java.util.List)17 TokenResult (com.alibaba.csp.sentinel.cluster.TokenResult)11 DegradeRule (com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule)9 BlockException (com.alibaba.csp.sentinel.slots.block.BlockException)6 Test (org.junit.jupiter.api.Test)6 ClusterFlowConfig (com.alibaba.csp.sentinel.slots.block.flow.ClusterFlowConfig)5 TypeReference (com.alibaba.fastjson.TypeReference)5 QuarkusUnitTest (io.quarkus.test.QuarkusUnitTest)5 Before (org.junit.Before)5 ParamFlowRule (com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule)4 ClusterMetric (com.alibaba.csp.sentinel.cluster.flow.statistic.metric.ClusterMetric)3 FlowRuleManager (com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager)3 AbstractTimeBasedTest (com.alibaba.csp.sentinel.test.AbstractTimeBasedTest)3 RateLimitDescriptor (io.envoyproxy.envoy.extensions.common.ratelimit.v3.RateLimitDescriptor)3 RateLimitResponse (io.envoyproxy.envoy.service.ratelimit.v3.RateLimitResponse)3 IOException (java.io.IOException)3