apllo监听

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.rcplatform.athena.platform.config.apollo;

import com.ctrip.framework.apollo.model.ConfigChange;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;
import java.lang.invoke.MethodHandles;
import java.util.Iterator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;

@Component
class ApolloConfigChanged implements ApplicationContextAware {
    private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
    private ApplicationContext applicationContext;

    ApolloConfigChanged() {
    }

    @ApolloConfigChangeListener({"application", "server.athena.platform"})
    private void configChangeHandler(ConfigChangeEvent changeEvent) {
        LOG.debug("Received Apollo config change event of namespace {}", changeEvent.getNamespace());
        Iterator var2 = changeEvent.changedKeys().iterator();

        while(var2.hasNext()) {
            String changedKey = (String)var2.next();
            ConfigChange configChange = changeEvent.getChange(changedKey);
            String oldValue = configChange.getOldValue();
            String newValue = configChange.getNewValue();
            LOG.debug("changedKey: {}, oldValue={}, newValue:{}", new Object[]{changedKey, oldValue, newValue});
        }

        this.refreshProperties(changeEvent);
        LOG.debug("Refreshed Spring configurations of Apollo namespace {}", changeEvent.getNamespace());
    }

    private void refreshProperties(ConfigChangeEvent changeEvent) {
        this.applicationContext.publishEvent(new EnvironmentChangeEvent(changeEvent.changedKeys()));
    }

    public void setApplicationContext(@NonNull ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}

注意:

private void refreshProperties(ConfigChangeEvent changeEvent) {
    this.applicationContext.publishEvent(new EnvironmentChangeEvent(changeEvent.changedKeys()));
}

至于为什么,search一下

你可能感兴趣的:(apllo监听)