An article to understand SpringCloud's configuration management framework Archaius

An article to understand SpringCloud's configuration management framework Archaius

1. What is Archaius?

Archaius is a Java class library that provides an API to obtain properties that can be dynamically changed at runtime

2. Archaius features

1. Dynamic properties

  1. You can use concise code to dynamically obtain type-specific attributes
  2. You can create a callback after modifying an attribute
DynamicIntProperty prop = 
      DynamicPropertyFactory.getInstance().getIntProperty("myProperty", DEFAULT_VALUE);
//prop.get() may change value at runtime

// callback
prop.addCallback(new Runnable() {
  public void run() {

2. Read configuration source data information cyclically

  1. DynamicPropertyFactory will obtain the configuration of the URL under the classpath or specified by the parameter at a certain interval (default 1 minute) to achieve dynamic update
  2. We can implement related interfaces ourselves to customize our own data sources, load and update logic regularly, etc.
PolledConfigurationSource source = createMyOwnSource();
AbstractPollingScheduler scheduler = createMyOwnScheduler();
ConfigurationManager.install(new DynamicConfiguration(source, scheduler));

3. Complete the realization of some configuration sources

  1. Complete the implementation of data sources such as JDBC, DynamoDB, zk, etc., out of the box
  2. You can customize your own configuration source, refer to:

4. Configuration and release context management

  1. is a manager used to manage system-wide configuration
  2. It is the core processing class of archaius, and the subsequent custom configuration source loading also needs to go through this class

5. High-throughput and thread-safe acquisition configuration

6. Support scala

3. simple hybrid configuration architecture

  1. The core concept of archaius is hybrid configuration, which can maintain one or more configuration sources, such as JDBC, REST, local configuration, zk, container configuration, etc.
  2. When a configuration exists in multiple configuration sources, the final configuration priority depends on the hierarchical order in the figure below; for example, if you configure property A (value=1) in the database, it is also configured in Attribute A (value=2), then from the hierarchical relationship in the figure below, the configuration of value=1 will finally take effect

4. use Archaius configuration

1. Introduce dependencies


2. Use a local file as the configuration source

  1. By default archaius can use the file in the classpath as the configuration source
  2. Of course, the in the jar will also be used as the configuration source, but this priority is lower than the current project classpath
  3. We can configure in the classpath, and dynamically obtain the configuration through the configuration method in 5

3. Use external URLS as configuration source

You can use the following configuration to specify the configuration source, which has a higher priority than


4. The default configuration parameters of archaius

  1. archaius.configurationSource.defaultFileName, the default value is; represents the local configuration file name
  2. archaius.fixedDelayPollingScheduler.initialDelayMills, the default is 30000; indicates the delay time to pull the configuration during initialization
  3. archaius.fixedDelayPollingScheduler.delayMills. The default is 60000; it means the interval time to pull the configuration regularly
  4. These three parameters can be reset through the system parameters

5. Use configuration

                .getStringProperty("test.archaius", "fail").get());


6. Summary of Configuration Manager

  1. ConfigurationManager is the manager used by archaius to manage all configurations, including the configuration of the management system, dynamicUrl, environment, and custom configuration sources (such as zk, db, etc.)
  2. ConfigurationManager is managed by instantiating a CompositionConfiguration
  3. We can get a system global configuration through ConfigurationManager.getConfigInstance(), including configuration data of all levels
  4. Specific source code will not be analyzed