当前位置: 首页 > news >正文

小记一下Zookeeper配置中心的部分原理

记录一下,这里其实很类似nacos的@Value,注解,可以结合去理解。

@Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        Class<?> beanClass = bean.getClass();
        Field[] fields = beanClass.getDeclaredFields();
        for (Field field : fields) {
            if (!field.isAnnotationPresent(DCCValue.class)) {
                continue;
            }

            DCCValue dccValue = field.getAnnotation(DCCValue.class);

            String value = dccValue.value();
            if (StringUtils.isBlank(value)) {
                throw new RuntimeException(field.getName() + " @DCCValue is not config value config case 「isSwitch/isSwitch:1」");
            }

            String[] splits = value.split(":");
            String key = splits[0];
            String defaultValue = splits.length == 2 ? splits[1] : null;

            try {
                // 判断当前节点是否存在,不存在则创建出 Zookeeper 节点
                String keyPath = BASE_CONFIG_PATH_CONFIG.concat("/").concat(key);
                if (null == client.checkExists().forPath(keyPath)) {
                    client.create().creatingParentsIfNeeded().forPath(keyPath);
                    if (StringUtils.isNotBlank(defaultValue)) {
                        field.setAccessible(true);
                        field.set(bean, defaultValue);
                        field.setAccessible(false);
                    }
                    log.info("DCC 节点监听 创建节点 {}", keyPath);
                } else {
                    String configValue = new String(client.getData().forPath(keyPath));
                    if (StringUtils.isNotBlank(configValue)) {
                        field.setAccessible(true);
                        field.set(bean, configValue);
                        field.setAccessible(false);
                        log.info("DCC 节点监听 设置配置 {} {} {}", keyPath, field.getName(), configValue);
                    }
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }

            dccObjGroup.put(BASE_CONFIG_PATH_CONFIG.concat("/").concat(key), bean);
        }
        return bean;
    }

 解答疑惑:

1. 平时使用配置中心时,注解标记后能读取到配置的原因

2. 注解中设置了默认值,当读取配置中心为空时,使用该默认值的原因


文章转载自:

http://bjPk6J6I.qbccg.cn
http://IiXcV8dS.qbccg.cn
http://Rgeh0Vmc.qbccg.cn
http://hEFR4Rvc.qbccg.cn
http://82MBKiLw.qbccg.cn
http://8anpnwn9.qbccg.cn
http://6dpSJtj9.qbccg.cn
http://xENiHsXL.qbccg.cn
http://bCE9K04P.qbccg.cn
http://BKGIL5rO.qbccg.cn
http://sziXo9F7.qbccg.cn
http://nOH7JbTg.qbccg.cn
http://wJllFMWB.qbccg.cn
http://sbTPT4cR.qbccg.cn
http://NQrwbJgb.qbccg.cn
http://j18WpfH1.qbccg.cn
http://8x97hflj.qbccg.cn
http://t6PPayfs.qbccg.cn
http://KMCpHViD.qbccg.cn
http://gpSNTqPK.qbccg.cn
http://kED0ZISY.qbccg.cn
http://BykYKD9d.qbccg.cn
http://49MD170X.qbccg.cn
http://rkql4FRg.qbccg.cn
http://iOGXfgWD.qbccg.cn
http://FzI5JA0z.qbccg.cn
http://CRjcHZCK.qbccg.cn
http://xMb5T5Xh.qbccg.cn
http://jFN7SUjq.qbccg.cn
http://Xwe01rlG.qbccg.cn
http://www.dtcms.com/a/65975.html

相关文章:

  • 使用服务器如何DNS呢
  • 【eNSP实战】基本ACL实现网络安全
  • 前端怎么测网速?
  • Python数据类型进阶——详解
  • 麒麟v10 ARM64架构系统升级mysql数据库从mysql-5.7.27到mysql-8.4.4图文教程
  • (vue)elementUi中el-upload上传附件之后 点击附件可下载
  • 拥抱AI未来:Hugging Face平台使用指南与实战技巧
  • 八叉树地图的原理与实现
  • 360安全软件拦截鼠标键盘模拟操作的解决方法
  • 青年公寓服务平台的设计与实现(代码+数据库+LW)
  • Linux下用多进程在GPU上跑Pytorch模型问题
  • 大模型在原发性急性闭角型青光眼预测及治疗方案制定中的应用研究报告
  • 字母金字塔
  • 深度学习核心技术深度解析
  • 【HarmonyOS NEXT】实现文字环绕动态文本效果
  • LeetCode455☞分发饼干
  • 第1关:整数对
  • 网络空间安全(28)风险评估实施
  • 《C#上位机开发从门外到门内》2-7:网络通信(TCP/IP、UDP)
  • Java学习路线
  • QT—环境监控系统
  • 直线导轨在数控机床中的使用方法
  • 【原创】springboot+vue校园新冠疫情统计管理系统设计与实现
  • 【Linux】浅谈冯诺依曼和进程
  • 【C++】list(上):list类的常用接口介绍
  • 人工智能与人的智能,思维模型分享【2】沉没成本
  • MySQL存入表情包异常,修改表、字段的字符集/排序规则
  • 【SpringBoot】MD5加盐算法的详解
  • 级联树SELECTTREE格式调整
  • 搭建基于chatgpt的问答系统