Search in sources :

Example 6 with FlowRule

use of com.alibaba.csp.sentinel.slots.block.flow.FlowRule in project Sentinel by alibaba.

the class AppLifecycleBean method onStart.

void onStart(@Observes StartupEvent ev) {
    LOGGER.info("The application is starting...");
    // Only for test here. Actually it's recommended to configure rules via data-source.
    FlowRule rule1 = new FlowRule().setCount(1).setGrade(RuleConstant.FLOW_GRADE_QPS).setResource("GET:/hello/txt").setLimitApp("default").as(FlowRule.class);
    FlowRule rule2 = new FlowRule("greeting2").setCount(1).setGrade(RuleConstant.FLOW_GRADE_QPS).as(FlowRule.class);
    FlowRuleManager.loadRules(Arrays.asList(rule1, rule2));
    DegradeRule degradeRule1 = new DegradeRule("greeting1").setCount(1).setGrade(CircuitBreakerStrategy.ERROR_COUNT.getType()).setTimeWindow(5).setStatIntervalMs(10000).setMinRequestAmount(1);
    DegradeRuleManager.loadRules(Arrays.asList(degradeRule1));
}
Also used : FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule) DegradeRule(com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule)

Example 7 with FlowRule

use of com.alibaba.csp.sentinel.slots.block.flow.FlowRule in project Sentinel by alibaba.

the class AsyncEntryDemo method initFlowRule.

private static void initFlowRule() {
    // Rule 1 won't take effect as the limitApp doesn't match.
    FlowRule rule1 = new FlowRule().setResource("test-another-sync-in-async").setLimitApp("originB").as(FlowRule.class).setCount(4).setGrade(RuleConstant.FLOW_GRADE_QPS);
    // Rule 2 will take effect.
    FlowRule rule2 = new FlowRule().setResource("test-another-async").setLimitApp("default").as(FlowRule.class).setCount(5).setGrade(RuleConstant.FLOW_GRADE_QPS);
    List<FlowRule> ruleList = Arrays.asList(rule1, rule2);
    FlowRuleManager.loadRules(ruleList);
}
Also used : FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule)

Example 8 with FlowRule

use of com.alibaba.csp.sentinel.slots.block.flow.FlowRule in project Sentinel by alibaba.

the class FooProviderBootstrap method initFlowRule.

private static void initFlowRule() {
    FlowRule flowRule = new FlowRule();
    flowRule.setResource(RES_KEY);
    flowRule.setCount(10);
    flowRule.setGrade(RuleConstant.FLOW_GRADE_QPS);
    flowRule.setLimitApp("default");
    FlowRuleManager.loadRules(Collections.singletonList(flowRule));
}
Also used : FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule)

Example 9 with FlowRule

use of com.alibaba.csp.sentinel.slots.block.flow.FlowRule in project Sentinel by alibaba.

the class PaceFlowDemo method initPaceFlowRule.

private static void initPaceFlowRule() {
    List<FlowRule> rules = new ArrayList<FlowRule>();
    FlowRule rule1 = new FlowRule();
    rule1.setResource(KEY);
    rule1.setCount(count);
    rule1.setGrade(RuleConstant.FLOW_GRADE_QPS);
    rule1.setLimitApp("default");
    /*
         * CONTROL_BEHAVIOR_RATE_LIMITER means requests more than threshold will be queueing in the queue,
         * until the queueing time is more than {@link FlowRule#maxQueueingTimeMs}, the requests will be rejected.
         */
    rule1.setControlBehavior(RuleConstant.CONTROL_BEHAVIOR_RATE_LIMITER);
    rule1.setMaxQueueingTimeMs(20 * 1000);
    rules.add(rule1);
    FlowRuleManager.loadRules(rules);
}
Also used : ArrayList(java.util.ArrayList) FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule)

Example 10 with FlowRule

use of com.alibaba.csp.sentinel.slots.block.flow.FlowRule in project Sentinel by alibaba.

the class ProviderFilterTest method configureRulesFor.

private void configureRulesFor(String resource, int count, String limitApp) {
    FlowRule rule = new FlowRule().setCount(count).setGrade(RuleConstant.FLOW_GRADE_QPS);
    rule.setResource(resource);
    if (StringUtil.isNotBlank(limitApp)) {
        rule.setLimitApp(limitApp);
    }
    FlowRuleManager.loadRules(Collections.singletonList(rule));
}
Also used : FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule)

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