Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

客户端读到老数据 #63

Open
chunlaiqingke opened this issue May 11, 2024 · 2 comments
Open

客户端读到老数据 #63

chunlaiqingke opened this issue May 11, 2024 · 2 comments

Comments

@chunlaiqingke
Copy link

chunlaiqingke commented May 11, 2024

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
Copy link
Member

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants