Netflix Archaius Dynamic Configuration

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-31 07:07:07

问题


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 Configuration Manager. When the values are updated in the xml file I want Hystrix configuration to be updated at runtime.

This is the guide I am following: https://github.com/Netflix/archaius/wiki/Users-Guide

I understand so far that I can use PolledConfigurationSource and the following code:

PolledConfigurationSource source = ...
AbstractPollingScheduler scheduler = ...
DynamicConfiguration configuration = new DynamicConfiguration(source, scheduler);
ConfigurationManager.install(configuration);

How do I point PolledConfigurationSource to an xml file to read the properties after a fixed time interval?


回答1:


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);
  }
}



回答2:


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



来源:https://stackoverflow.com/questions/35712393/netflix-archaius-dynamic-configuration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!