framework中的sentinel

引入切面:

 

framework中的sentinel

 

切面+sentinel-web-servlet

private void initDataSource() {
        String zkUrl = zaSentinelConfig.getDatacource().getAddress();
        String appName = environment.getProperty("spring.application.name");
        LOGGER.info("=================={} SentinelDataSource init, zookeeper info:{}===========", appName, zkUrl);

        // flow
        ReadableDataSource<String, List<FlowRule>> flowRuleDataSource = new ZookeeperDataSource<>(zkUrl,
                ZookeeperConfigUtil.getPath(appName, RuleTypeEnum.FLOW), source -> JSON.parseObject(source, new TypeReference<List<FlowRule>>() {}));
        FlowRuleManager.register2Property(flowRuleDataSource.getProperty());

        // degrade
        ReadableDataSource<String, List<DegradeRule>> degradeRuleDataSource = new ZookeeperDataSource<>(zkUrl,
                ZookeeperConfigUtil.getPath(appName, RuleTypeEnum.DEGRADE), source -> JSON.parseObject(source, new TypeReference<List<DegradeRule>>() {}));
        DegradeRuleManager.register2Property(degradeRuleDataSource.getProperty());

        // system
        ReadableDataSource<String, List<SystemRule>> systemRuleDataSource = new ZookeeperDataSource<>(zkUrl,
                ZookeeperConfigUtil.getPath(appName, RuleTypeEnum.SYSTEM), source -> JSON.parseObject(source, new TypeReference<List<SystemRule>>() {}));
        SystemRuleManager.register2Property(systemRuleDataSource.getProperty());

        // authority
        ReadableDataSource<String, List<AuthorityRule>> authorityRuleDataSource = new ZookeeperDataSource<>(zkUrl,
                ZookeeperConfigUtil.getPath(appName, RuleTypeEnum.AUTHORITY), source -> JSON.parseObject(source, new TypeReference<List<AuthorityRule>>() {}));
        AuthorityRuleManager.register2Property(authorityRuleDataSource.getProperty());

        // loadbalance
        ReadableDataSource<String, List<LoadBalanceRule>> loadBalanceRuleDataSource =
                new ZookeeperDataSource<>(zkUrl, ZookeeperConfigUtil.getPath(appName, RuleTypeEnum.LOAD_BALANCE),
                        source -> JSON.parseObject(source, new TypeReference<List<LoadBalanceRule>>() {}));
        LoadBalanceRuleManager.register2Property(loadBalanceRuleDataSource.getProperty());
    }

 没啥东西

 

上一篇:String转java泛型对象


下一篇:java 解析json 万能型