com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowItem Java Examples

The following examples show how to use com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowItem. 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: ParamFlowQpsDemo.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 6 votes vote down vote up
private static void initParamFlowRules() {
    // QPS mode, threshold is 5 for every frequent "hot spot" parameter in index 0 (the first arg).
    ParamFlowRule rule = new ParamFlowRule(RESOURCE_KEY)
        .setParamIdx(0)
        .setGrade(RuleConstant.FLOW_GRADE_QPS)
        //.setDurationInSec(3)
        //.setControlBehavior(RuleConstant.CONTROL_BEHAVIOR_RATE_LIMITER)
        //.setMaxQueueingTimeMs(600)
        .setCount(5);

    // We can set threshold count for specific parameter value individually.
    // Here we add an exception item. That means: QPS threshold of entries with parameter `PARAM_B` (type: int)
    // in index 0 will be 10, rather than the global threshold (5).
    ParamFlowItem item = new ParamFlowItem().setObject(String.valueOf(PARAM_B))
        .setClassType(int.class.getName())
        .setCount(10);
    rule.setParamFlowItemList(Collections.singletonList(item));
    ParamFlowRuleManager.loadRules(Collections.singletonList(rule));
}
 
Example #2
Source File: ParamFlowQpsDemo.java    From Sentinel with Apache License 2.0 6 votes vote down vote up
private static void initParamFlowRules() {
    // QPS mode, threshold is 5 for every frequent "hot spot" parameter in index 0 (the first arg).
    ParamFlowRule rule = new ParamFlowRule(RESOURCE_KEY)
        .setParamIdx(0)
        .setGrade(RuleConstant.FLOW_GRADE_QPS)
        //.setDurationInSec(3)
        //.setControlBehavior(RuleConstant.CONTROL_BEHAVIOR_RATE_LIMITER)
        //.setMaxQueueingTimeMs(600)
        .setCount(5);

    // We can set threshold count for specific parameter value individually.
    // Here we add an exception item. That means: QPS threshold of entries with parameter `PARAM_B` (type: int)
    // in index 0 will be 10, rather than the global threshold (5).
    ParamFlowItem item = new ParamFlowItem().setObject(String.valueOf(PARAM_B))
        .setClassType(int.class.getName())
        .setCount(10);
    rule.setParamFlowItemList(Collections.singletonList(item));
    ParamFlowRuleManager.loadRules(Collections.singletonList(rule));
}
 
Example #3
Source File: FreqParamFlowSimulate.java    From sentinel-tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化热点限流的规则
 */
private void initHotParamFlowRules() {
    // 设置热点参数的规则,qps 模式,阈值为5
    ParamFlowRule rule = new ParamFlowRule(resourceName)
            .setParamIdx(0)
            .setGrade(RuleConstant.FLOW_GRADE_QPS)
            .setCount(5);
    // 对userId=111的参数设置例外项,可以为该用户id的值单独设置阈值
    ParamFlowItem item = new ParamFlowItem().setObject(String.valueOf(111))
            .setClassType(int.class.getName())
            .setCount(10);
    rule.setParamFlowItemList(Collections.singletonList(item));
    ParamFlowRuleManager.loadRules(Collections.singletonList(rule));
}
 
Example #4
Source File: ParamFlowRuleEntity.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 4 votes vote down vote up
@JsonIgnore
public List<ParamFlowItem> getParamFlowItemList() {
    return rule.getParamFlowItemList();
}
 
Example #5
Source File: GatewayRuleConverter.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 4 votes vote down vote up
static ParamFlowItem generateNonMatchPassParamItem() {
    return new ParamFlowItem().setClassType(String.class.getName())
        .setCount(1000_0000)
        .setObject(SentinelGatewayConstants.GATEWAY_NOT_MATCH_PARAM);
}
 
Example #6
Source File: GatewayRuleConverter.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 4 votes vote down vote up
static ParamFlowItem generateNonMatchBlockParamItem() {
    return new ParamFlowItem().setClassType(String.class.getName())
        .setCount(0)
        .setObject(SentinelGatewayConstants.GATEWAY_NOT_MATCH_PARAM);
}
 
Example #7
Source File: ParamFlowRuleEntity.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
@JsonIgnore
@JSONField(serialize = false)
public List<ParamFlowItem> getParamFlowItemList() {
    return rule.getParamFlowItemList();
}
 
Example #8
Source File: GatewayRuleConverter.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
static ParamFlowItem generateNonMatchPassParamItem() {
    return new ParamFlowItem().setClassType(String.class.getName())
        .setCount(1000_0000)
        .setObject(SentinelGatewayConstants.GATEWAY_NOT_MATCH_PARAM);
}
 
Example #9
Source File: GatewayRuleConverter.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
static ParamFlowItem generateNonMatchBlockParamItem() {
    return new ParamFlowItem().setClassType(String.class.getName())
        .setCount(0)
        .setObject(SentinelGatewayConstants.GATEWAY_NOT_MATCH_PARAM);
}