Search in sources :

Example 1 with Listener

use of com.alibaba.nacos.api.config.listener.Listener in project blog_demos by zq2599.

the class RouteConfigListener method dynamicRouteByNacosListener.

@PostConstruct
public void dynamicRouteByNacosListener() throws NacosException {
    ConfigService configService = NacosFactory.createConfigService(serverAddr);
    // 添加监听,nacos上的配置变更后会执行
    configService.addListener(dataId, group, new Listener() {

        public void receiveConfigInfo(String configInfo) {
            // 解析和处理都交给RouteOperator完成
            routeOperator.refreshAll(configInfo);
        }

        public Executor getExecutor() {
            return null;
        }
    });
    // 获取当前的配置
    String initConfig = configService.getConfig(dataId, group, 5000);
    // 立即更新
    routeOperator.refreshAll(initConfig);
}
Also used : ConfigService(com.alibaba.nacos.api.config.ConfigService) Listener(com.alibaba.nacos.api.config.listener.Listener) Executor(java.util.concurrent.Executor) PostConstruct(javax.annotation.PostConstruct)

Example 2 with Listener

use of com.alibaba.nacos.api.config.listener.Listener in project incubator-shenyu by apache.

the class NacosServerRegisterRepository method subscribeMetadata.

private void subscribeMetadata(final String serviceConfigName) {
    registerMetadata(readData(serviceConfigName));
    LOGGER.info("subscribe metadata: {}", serviceConfigName);
    try {
        configService.addListener(serviceConfigName, defaultGroup, new Listener() {

            @Override
            public Executor getExecutor() {
                return null;
            }

            @Override
            public void receiveConfigInfo(final String config) {
                registerMetadata(config);
            }
        });
    } catch (NacosException e) {
        throw new ShenyuException(e);
    }
}
Also used : Listener(com.alibaba.nacos.api.config.listener.Listener) Executor(java.util.concurrent.Executor) ShenyuException(org.apache.shenyu.common.exception.ShenyuException) NacosException(com.alibaba.nacos.api.exception.NacosException)

Example 3 with Listener

use of com.alibaba.nacos.api.config.listener.Listener in project hippo4j by longtai-cn.

the class NacosCloudRefresherHandler method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    Map<String, String> nacosConfig = bootstrapCoreProperties.getNacos();
    nacosConfigManager.getConfigService().addListener(nacosConfig.get("data-id"), nacosConfig.get("group"), new Listener() {

        @Override
        public Executor getExecutor() {
            return dynamicRefreshExecutorService;
        }

        @Override
        public void receiveConfigInfo(String configInfo) {
            dynamicRefresh(configInfo);
        }
    });
}
Also used : Listener(com.alibaba.nacos.api.config.listener.Listener) Executor(java.util.concurrent.Executor)

Example 4 with Listener

use of com.alibaba.nacos.api.config.listener.Listener in project hippo4j by longtai-cn.

the class NacosRefresherHandler method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    Map<String, String> nacosConfig = bootstrapCoreProperties.getNacos();
    configService.addListener(nacosConfig.get("data-id"), nacosConfig.get("group"), new Listener() {

        @Override
        public Executor getExecutor() {
            return dynamicRefreshExecutorService;
        }

        @Override
        public void receiveConfigInfo(String configInfo) {
            dynamicRefresh(configInfo);
        }
    });
}
Also used : Listener(com.alibaba.nacos.api.config.listener.Listener) Executor(java.util.concurrent.Executor)

Example 5 with Listener

use of com.alibaba.nacos.api.config.listener.Listener in project hummer-framework by hummer-team.

the class ConfigTest method main.

public static void main(String[] args) throws NacosException, IOException {
    String serverAddr = "http://192.168.38.148:8848";
    String dataId = "mytest_01";
    String group = "test_01";
    Properties properties = new Properties();
    properties.put("serverAddr", serverAddr);
    ConfigService configService = NacosFactory.createConfigService(properties);
    String content = configService.getConfig(dataId, group, 5000);
    System.out.println(content);
    configService.addListener("data_01", "G_1", new Listener() {

        @Override
        public Executor getExecutor() {
            return null;
        }

        @Override
        public void receiveConfigInfo(String configInfo) {
            System.out.println("recieve22:" + configInfo);
        }
    });
    configService.addListener(dataId, group, new Listener() {

        @Override
        public void receiveConfigInfo(String configInfo) {
            System.out.println("recieve:" + configInfo);
        }

        @Override
        public Executor getExecutor() {
            return null;
        }
    });
    System.in.read();
}
Also used : ConfigService(com.alibaba.nacos.api.config.ConfigService) Listener(com.alibaba.nacos.api.config.listener.Listener) Executor(java.util.concurrent.Executor) Properties(java.util.Properties)

Aggregations

Listener (com.alibaba.nacos.api.config.listener.Listener)45 Executor (java.util.concurrent.Executor)22 Test (org.junit.Test)14 Properties (java.util.Properties)13 ConfigService (com.alibaba.nacos.api.config.ConfigService)11 AbstractListener (com.alibaba.nacos.api.config.listener.AbstractListener)8 NacosException (com.alibaba.nacos.api.exception.NacosException)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 ConfigFilterChainManager (com.alibaba.nacos.client.config.filter.impl.ConfigFilterChainManager)4 ConnectionEventListener (com.alibaba.nacos.common.remote.client.ConnectionEventListener)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 NacosConfigProperties (com.alibaba.cloud.nacos.NacosConfigProperties)2 AbstractSharedListener (com.alibaba.nacos.api.config.listener.AbstractSharedListener)2 ConfigResponse (com.alibaba.nacos.client.config.filter.impl.ConfigResponse)2 DoorGoodConfig (com.hummer.doorgod.service.domain.configuration.DoorGoodConfig)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 List (java.util.List)2 PostConstruct (javax.annotation.PostConstruct)2