Netflix Archaius Dynamic Configuration

后端 未结 2 1913
旧巷少年郎
旧巷少年郎 2021-01-28 05:42

I am integrating Hystrix in to my existing project and I want to read the configuration values from an xml file instead of feeding the configuration properties using Configurati

相关标签:
2条回答
  • 2021-01-28 06:26

    Following code did the trick for me

    private void initializeConfiguration() {
    
        // FixedDelayPollingScheduler is initialized with default system
        // settings
        // Fixed delay in milliseconds between two reads of the configuration
        // URLs
        // archaius.fixedDelayPollingScheduler.delayMills = 60000
        // Initial delay in milliseconds of reading from the configuration
        // source
        // archaius.fixedDelayPollingScheduler.initialDelayMills = 30000
        AbstractPollingScheduler scheduler = new FixedDelayPollingScheduler();
    
        // Configuration source that brings dynamic changes to the configuration
        // via polling
        PolledConfigurationSource source = new XMLPolledConfigurationSource();
    
        // Configuration that polls a PolledConfigurationSource according to the
        // schedule set by a scheduler
        DynamicConfiguration configuration = new DynamicConfiguration(source, scheduler);
    
        ConfigurationManager.install(configuration);
    
        // Registering configuration with an MBean and will be accessible for
        // read and update via JConsole
        ConfigJMXManager.registerConfigMbean(configuration);
    }
    

    XMLPolledConfigurationSource source code

    public class XMLPolledConfigurationSource implements PolledConfigurationSource {
    
    @SuppressWarnings("static-access")
    @Override
    public PollResult poll(boolean inital, Object checkPoint) throws Exception {
        PollResult pollResult = null;
        Map<String, Object> map = new HashMap<>();
        // Code to read content from the resource
        return pollResult.createFull(map);
      }
    }
    
    0 讨论(0)
  • 2021-01-28 06:37

    Have you tried using setting this system variable as per documentation? -Darchaius.configurationSource.additionalUrls=file:///apps/myapp/application.xml By documentation I am referring to the Getting started web page https://github.com/Netflix/archaius/wiki/Getting-Started

    0 讨论(0)
提交回复
热议问题