美文网首页
Nacos 配置变更逻辑

Nacos 配置变更逻辑

作者: 小周爱吃瓜 | 来源:发表于2022-07-07 23:50 被阅读0次
    • LongPollingService
    public LongPollingService() {
            allSubs = new ConcurrentLinkedQueue<ClientLongPolling>();
            
            ConfigExecutor.scheduleLongPolling(new StatTask(), 0L, 10L, TimeUnit.SECONDS);
            
            // Register LocalDataChangeEvent to NotifyCenter.
            NotifyCenter.registerToPublisher(LocalDataChangeEvent.class, NotifyCenter.ringBufferSize);
            
            // Register A Subscriber to subscribe LocalDataChangeEvent.
            NotifyCenter.registerSubscriber(new Subscriber() {
                
                @Override
                public void onEvent(Event event) {
                    if (isFixedPolling()) {
                        // Ignore.
                    } else {
                        if (event instanceof LocalDataChangeEvent) {
                            LocalDataChangeEvent evt = (LocalDataChangeEvent) event;
                            ConfigExecutor.executeLongPolling(new DataChangeTask(evt.groupKey, evt.isBeta, evt.betaIps));
                        }
                    }
                }
                
                @Override
                public Class<? extends Event> subscribeType() {
                    return LocalDataChangeEvent.class;
                }
            });
            
        }
    

    构造中分为定时轮训和LocalDataChangeEvent两种方式.

    ConfigController. publishConfig -> NotifyCenter.publishEvent()->
    发布了时间后 1. 同步其他集群节点 2. 出发了LocalDataChangeEvent,开启任务,提前generatel响应了长轮训的的http请求。 返回结果,相当于http主动的推送了 过来.

    • ConfigController
      LongPollingService ClientWorker ConfigService ConfigExecutor

    详情看fox老师的笔记.


    Nacos配置中心源码分析.jpg

    相关文章

      网友评论

          本文标题:Nacos 配置变更逻辑

          本文链接:https://www.haomeiwen.com/subject/dfembrtx.html