apolloconfig / apollo-java

Apollo Java Clients
Apache License 2.0
40 stars 72 forks source link

客户端读到老数据 #63

Closed chunlaiqingke closed 4 months ago

chunlaiqingke commented 6 months ago
ConfigService.getAppConfig().addChangeListener(new ConfigChangeListener() {
            @Override
            public void onChange(ConfigChangeEvent configChangeEvent) {
                String newValue = configChangeEvent.getChange("someKey").getNewValue();
                System.out.println("event-:  ");
                System.out.println(newValue);
                String application = ConfigService.getConfigFile("application", ConfigFileFormat.Properties).getContent();
                System.out.println("configservice-:  ");
                System.out.println(application);
            }
        });

        ConfigService.getConfigFile("application", ConfigFileFormat.Properties).addChangeListener(new ConfigFileChangeListener() {
            @Override
            public void onChange(ConfigFileChangeEvent changeEvent) {
                System.out.println("-----------------");
                System.out.println("event-:  ");
                String newValue = changeEvent.getNewValue();
                System.out.println(newValue);
                String somekey = ConfigService.getAppConfig().getProperty("someKey", "");
                System.out.println("configservice-:  ");
                System.out.println(somekey);
            }
        });

image image

当config监听器中使用configfile去获取配置时,读到老的配置,是同一个namespace

nobodyiam commented 6 months ago

Config 和 ConfigFile 是两个不同的对象,独立更新的,代码改成这样应该就一致了

ConfigService.getAppConfig().addChangeListener(new ConfigChangeListener() {
            @Override
            public void onChange(ConfigChangeEvent configChangeEvent) {
                String newValue = configChangeEvent.getChange("someKey").getNewValue();
                System.out.println("event-:  ");
                System.out.println(newValue);
                String somekey = ConfigService.getAppConfig().getProperty("someKey", "");
                System.out.println("configservice-:  ");
                System.out.println(somekey);
            }
        });

        ConfigService.getConfigFile("application", ConfigFileFormat.Properties).addChangeListener(new ConfigFileChangeListener() {
            @Override
            public void onChange(ConfigFileChangeEvent changeEvent) {
                System.out.println("-----------------");
                System.out.println("event-:  ");
                String newValue = changeEvent.getNewValue();
                System.out.println(newValue);
                String application = ConfigService.getConfigFile("application", ConfigFileFormat.Properties).getContent();
                System.out.println("configservice-:  ");
                System.out.println(application);
            }
        });
chunlaiqingke commented 6 months ago

可以将DefaultConfig和PropertiesConfigFile的同名namespace的Repository合并吗,感觉可行

stale[bot] commented 5 months ago

This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 7 days unless it is tagged "help wanted" or other activity occurs. Thank you for your contributions.

stale[bot] commented 4 months ago

This issue has been automatically closed because it has not had activity in the last 7 days. If this issue is still valid, please ping a maintainer and ask them to label it as "help wanted". Thank you for your contributions.