use of com.alibaba.csp.sentinel.slots.block.authority.AuthorityRule in project Sentinel by alibaba.
the class AuthorityDemo method initBlackRules.
private static void initBlackRules() {
AuthorityRule rule = new AuthorityRule();
rule.setResource(RESOURCE_NAME);
rule.setStrategy(RuleConstant.AUTHORITY_BLACK);
rule.setLimitApp("appA,appB");
AuthorityRuleManager.loadRules(Collections.singletonList(rule));
}
use of com.alibaba.csp.sentinel.slots.block.authority.AuthorityRule in project learn-simple by muggle0.
the class SentileConfig method initRules.
@PostConstruct
private void initRules() throws Exception {
FlowRule rule1 = new FlowRule();
rule1.setResource("test.hello");
rule1.setGrade(RuleConstant.FLOW_GRADE_QPS);
// 每秒调用最大次数为 1 次
rule1.setCount(1);
List<FlowRule> rules = new ArrayList<>();
// DegradeRuleManager.loadRules(List< DegradeRule > rules); // 修改降级规则
rules.add(rule1);
// 将控制规则载入到 Sentinel
// AuthorityRuleManager
FlowRuleManager.loadRules(rules);
/* ReadableDataSource<String, List<FlowRule>> flowRuleDataSource = new NacosDataSource<>(remoteAddress, groupId, dataId,
source -> JSON.parseObject(source, new TypeReference<List<FlowRule>>() {
}));*/
// FlowRuleManager.register2Property(flowRuleDataSource.getProperty());
DegradeRule rule = new DegradeRule();
List<DegradeRule> rules1 = new ArrayList<>();
rule.setResource("test.hello");
rule.setCount(0.01);
// 秒级RT
rule.setGrade(RuleConstant.DEGRADE_GRADE_RT);
rule.setTimeWindow(10);
rules1.add(rule);
DegradeRuleManager.loadRules(rules1);
ParamFlowRule paramFlowRule = new ParamFlowRule("resourceName").setParamIdx(0).setCount(5);
// 单独设置限流 QPS,设置param 参数限流规则
ParamFlowItem item = new ParamFlowItem().setObject("param").setClassType(int.class.getName()).setCount(10);
paramFlowRule.setParamFlowItemList(Collections.singletonList(item));
ParamFlowRuleManager.loadRules(Collections.singletonList(paramFlowRule));
SystemRule systemRule = new SystemRule();
systemRule.setHighestCpuUsage(0.8);
systemRule.setAvgRt(10);
systemRule.setQps(10);
systemRule.setMaxThread(10);
systemRule.setHighestSystemLoad(2.5);
SystemRuleManager.loadRules(Collections.singletonList(systemRule));
AuthorityRule authorityRule = new AuthorityRule();
authorityRule.setStrategy(RuleConstant.AUTHORITY_BLACK);
authorityRule.setLimitApp("127.0.0.1");
authorityRule.setResource("test.hello");
AuthorityRuleManager.loadRules(Collections.singletonList(authorityRule));
// ContextUtil.enter("xxx", "origin");
}
use of com.alibaba.csp.sentinel.slots.block.authority.AuthorityRule in project spring-boot-student by wyh-spring-ecosystem-student.
the class JsonSerializeTest method authorityRuleJsonSerializeTest.
@Test
public void authorityRuleJsonSerializeTest() {
AuthorityRuleEntity emptyRule = new AuthorityRuleEntity();
Assert.assertTrue("{}".equals(JSON.toJSONString(emptyRule)));
AuthorityRuleEntity authorityRule = new AuthorityRuleEntity();
AuthorityRule rule = new AuthorityRule();
rule.setStrategy(0).setLimitApp("default").setResource("rs");
authorityRule.setRule(rule);
Assert.assertTrue("{\"rule\":{\"limitApp\":\"default\",\"resource\":\"rs\",\"strategy\":0}}".equals(JSON.toJSONString(authorityRule)));
}
use of com.alibaba.csp.sentinel.slots.block.authority.AuthorityRule in project Sentinel by alibaba.
the class AuthorityDemo method initWhiteRules.
private static void initWhiteRules() {
AuthorityRule rule = new AuthorityRule();
rule.setResource(RESOURCE_NAME);
rule.setStrategy(RuleConstant.AUTHORITY_WHITE);
rule.setLimitApp("appA,appE");
AuthorityRuleManager.loadRules(Collections.singletonList(rule));
}
use of com.alibaba.csp.sentinel.slots.block.authority.AuthorityRule in project Sentinel by alibaba.
the class JsonSerializeTest method authorityRuleJsonSerializeTest.
@Test
public void authorityRuleJsonSerializeTest() {
AuthorityRuleEntity emptyRule = new AuthorityRuleEntity();
Assert.assertTrue("{}".equals(JSON.toJSONString(emptyRule)));
AuthorityRuleEntity authorityRule = new AuthorityRuleEntity();
AuthorityRule rule = new AuthorityRule();
rule.setStrategy(0).setLimitApp("default").setResource("rs");
authorityRule.setRule(rule);
Assert.assertTrue("{\"rule\":{\"limitApp\":\"default\",\"resource\":\"rs\",\"strategy\":0}}".equals(JSON.toJSONString(authorityRule)));
}
Aggregations