Convert Figma logo to code with AI

Netflix logoarchaius

Library for configuration management API

2,466
485
2,466
38

Top Related Projects

External configuration (server and client) for Spring Cloud

29,056

Apollo is a reliable configuration management system suitable for microservice configuration management scenarios.

6,161

configuration library for JVM languages using HOCON files

47,616

Distributed reliable key-value store for the most critical data of a distributed system

Quick Overview

Archaius is a configuration management library developed by Netflix. It provides dynamic, typed properties and configuration management for distributed systems, allowing for runtime changes to configuration without requiring application restarts.

Pros

  • Dynamic property updates without application restarts
  • Integration with various configuration sources (e.g., properties files, databases, ZooKeeper)
  • Type-safe configuration access
  • Supports hierarchical configurations and fallback mechanisms

Cons

  • Complexity in setup and configuration for advanced use cases
  • Limited documentation and examples for newer versions
  • Dependency on other Netflix OSS libraries for some features
  • Less active development in recent years

Code Examples

  1. Basic property access:
DynamicStringProperty myProperty = DynamicPropertyFactory.getInstance()
    .getStringProperty("my.property", "default value");

String value = myProperty.get();
  1. Callback for property changes:
DynamicIntProperty maxConnections = DynamicPropertyFactory.getInstance()
    .getIntProperty("max.connections", 100);

maxConnections.addCallback(() -> {
    System.out.println("Max connections updated to: " + maxConnections.get());
});
  1. Custom configuration source:
AbstractPollingScheduler scheduler = new FixedDelayPollingScheduler();
PolledConfigurationSource source = new MyCustomConfigSource();
DynamicConfiguration configuration = new DynamicConfiguration(source, scheduler);
ConfigurationManager.install(configuration);

Getting Started

  1. Add Archaius dependency to your project:
<dependency>
    <groupId>com.netflix.archaius</groupId>
    <artifactId>archaius-core</artifactId>
    <version>0.7.7</version>
</dependency>
  1. Create a config.properties file in your classpath:
my.property=Hello, Archaius!
  1. Use Archaius in your code:
import com.netflix.config.DynamicPropertyFactory;
import com.netflix.config.DynamicStringProperty;

public class MyApp {
    public static void main(String[] args) {
        DynamicStringProperty myProperty = DynamicPropertyFactory.getInstance()
            .getStringProperty("my.property", "default value");
        
        System.out.println(myProperty.get());
    }
}

This setup provides basic functionality. For more advanced features, refer to the Archaius documentation.

Competitor Comparisons

External configuration (server and client) for Spring Cloud

Pros of Spring Cloud Config

  • Centralized configuration management with support for multiple environments
  • Seamless integration with Spring Boot applications
  • Built-in support for version control systems like Git

Cons of Spring Cloud Config

  • Steeper learning curve for non-Spring developers
  • Requires additional setup and infrastructure compared to Archaius
  • May be overkill for smaller applications or simpler configuration needs

Code Comparison

Spring Cloud Config:

@EnableConfigServer
@SpringBootApplication
public class ConfigServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(ConfigServerApplication.class, args);
    }
}

Archaius:

DynamicStringProperty myProperty = DynamicPropertyFactory.getInstance()
    .getStringProperty("my.property", "default");
String value = myProperty.get();

Spring Cloud Config focuses on centralized configuration management with a dedicated server, while Archaius provides a more lightweight approach to dynamic property management within applications. Spring Cloud Config offers better integration with Spring ecosystems and version control systems, but may require more setup. Archaius is simpler to integrate into existing applications and provides dynamic property updates without a separate server, but lacks some of the advanced features and centralized management capabilities of Spring Cloud Config.

29,056

Apollo is a reliable configuration management system suitable for microservice configuration management scenarios.

Pros of Apollo

  • More comprehensive configuration management system with a user-friendly web interface
  • Supports real-time configuration changes without service restarts
  • Offers multi-environment and multi-cluster configuration management

Cons of Apollo

  • More complex setup and infrastructure requirements
  • Steeper learning curve due to its extensive feature set
  • May be overkill for smaller projects or simpler configuration needs

Code Comparison

Apollo configuration retrieval:

Config config = ConfigService.getAppConfig();
String someKey = config.getProperty("someKey", "defaultValue");

Archaius configuration retrieval:

DynamicStringProperty someKey = DynamicPropertyFactory.getInstance()
    .getStringProperty("someKey", "defaultValue");
String value = someKey.get();

Both Apollo and Archaius are configuration management systems, but Apollo offers a more comprehensive solution with a web interface and advanced features. Archaius, being part of the Netflix OSS stack, integrates well with other Netflix libraries and is lighter weight.

Apollo is better suited for larger, more complex applications with diverse configuration needs across multiple environments. Archaius is simpler to set up and use, making it a good choice for smaller projects or those already using other Netflix OSS components.

The code comparison shows that both libraries offer similar basic functionality for retrieving configuration values, with slight differences in syntax and method names.

6,161

configuration library for JVM languages using HOCON files

Pros of Config

  • Simple and lightweight with minimal dependencies
  • Supports HOCON (Human-Optimized Config Object Notation) for more flexible configuration
  • Strong typing support with automatic type conversion

Cons of Config

  • Lacks dynamic configuration updates at runtime
  • No built-in support for distributed environments or service discovery

Code Comparison

Config:

val conf = ConfigFactory.load()
val port = conf.getInt("myapp.server.port")
val url = conf.getString("myapp.remote.url")

Archaius:

DynamicPropertyFactory properties = DynamicPropertyFactory.getInstance();
int port = properties.getIntProperty("myapp.server.port", 8080).get();
String url = properties.getStringProperty("myapp.remote.url", "http://default.com").get();

Key Differences

  • Config focuses on simplicity and type safety, while Archaius emphasizes dynamic configuration management
  • Archaius provides more advanced features for distributed systems and service discovery
  • Config uses HOCON format, which is more human-friendly compared to Archaius' properties-based approach
  • Archaius offers real-time configuration updates, whereas Config typically requires application restart for changes

Use Cases

  • Choose Config for simpler applications or when HOCON format is preferred
  • Opt for Archaius in microservices architectures or when dynamic configuration updates are crucial
47,616

Distributed reliable key-value store for the most critical data of a distributed system

Pros of etcd

  • Distributed key-value store with strong consistency and high availability
  • Supports complex operations like atomic compare-and-swap and multi-key transactions
  • Built-in support for cluster management and leader election

Cons of etcd

  • Higher complexity and resource requirements for setup and maintenance
  • May be overkill for simpler configuration management needs
  • Steeper learning curve compared to Archaius

Code Comparison

etcd (Go):

cli, _ := clientv3.New(clientv3.Config{Endpoints: []string{"localhost:2379"}})
defer cli.Close()
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
_, err := cli.Put(ctx, "key", "value")
cancel()

Archaius (Java):

DynamicStringProperty myProperty = DynamicPropertyFactory.getInstance()
    .getStringProperty("my.property", "default");
String value = myProperty.get();

Summary

etcd is a distributed key-value store focused on consistency and reliability, while Archaius is primarily a configuration management library. etcd offers more advanced features for distributed systems but requires more setup. Archaius provides a simpler API for configuration management but may lack some of etcd's advanced capabilities.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Archaius is a configuration library for accessing a mixture of static as well as dynamic configurations as a single configuration unit.

There are two key concepts to note:

  • Properties that can be read by your code.
  • Configurations that organize properties into objects you can bootstrap your application with.

Features

  • Lock-free property reads.
  • Dependency Injection (i.e., Guice) friendly so you don't have to rely on static code execution.

2.x Changes

  • Not backwards compatible with 1.x.
  • Clean separation of API and backing configurations (i.e. commons-configuration, typesafe-configuration, etc).
  • Minimal external dependencies.
  • Improved bootstrapping process that doesn't rely on class loading.

Getting Started

Archaius provides a set of specialized configuration classes that may be combined using com.netflix.archaius.api.config.CompositeConfig into a specific override structure.
Check out com.netflix.archaius.ProxyFactoryTest (under archaius2-core/test/java/) for an example on how to bootstrap a config and access dynamic properties from it.

Accessing configuration

All com.netflix.archaius.api.Config (under archaius2-api/) derived classes provide access to their underlying configuration via the numerous getString(), getInt(), getBoolean() methods.
In addition to basic primitives and collections Config will allow parsing to any type that has a constructor that takes a single String argument or a static valueOf(String.class) method.

Replacements

Archaius supports standard variable replacement syntax such as ${other.property.name}.

Configuration loaders

Archaius has a default built in loader for .properties files but can also be extended with custom property specifications such as HOCON. In addition multiple contextual overrides for a single configuration resource name may be derived using a com.netflix.archaius.api.CascadeStrategy. The strategy may also specify replacements from already loaded configurations (such as System and Environment properties).

Dynamic Properties

One of the core differentiators between Archaius and other configuration libraries is its support for dynamically changing configuration. Traditionally applications require a restart whenever configuration changes. This can result in unnecessary service interruption during minor configuration changes, such as timeout values. Through Archaius, code can have direct access to the most recent configuration without the need to restart. In addition, code can react to configuration changes by registering a change handler.

Dynamic configuration support is split into the configuration loading and property value resolution.

Configuration loading

When adding a DynamicConfig derived configuration CompositeConfig will automatically register for configuration change notifications and incorporate new values into the main configuration.
Archaius provides a base PollingDynamicConfig for use with configuration sources that are polled frequently to refresh the entire configuration snapshot. Implement Config directly for fine grained configuration sources, such as ZooKeeper, which support updates at the individual property granularity.

config.addConfig(new PollingDynamicConfig(
            "REMOTE", 
            new URLConfigReader("http://remoteconfigservice/snapshot"), 
            new FixedPollingStrategy(30, TimeUnit.SECONDS)) 

Property access

Use the Property API for optimized access to any property that is expected to be updated at runtime. Access to dynamic configuration follows two access patterns. The first (and most common) is to get the most recent value directly from a Property object.
Property optimizes caching of the resolved property value (from the hierarchy) and is much more efficient than calling the Config object for frequently accessed properties.
The second, and more advanced, access pattern is to react to property value changes via a com.netflix.archaius.api.PropertyListener.

To create a fast property factory using any Config as the source

DefaultPropertyFactory factory = DefaultPropertyFactory.from(config);

To create a com.netflix.archaius.api.Property object

Property<Integer> timeout = factory.getProperty("server.timeout").asInteger(DEFAULT_TIMEOUT_VALUE);

To access the cached property value

Thread.sleep(timeout.get());

To react to property change notification

Property<Integer> timeout = factory
    .getProperty("server.timeout")
    .asInteger() 
    .addListener(new PropertyListener<Integer>() {
        public void onChange(Integer value) {
            socket.setReadTimeout(value);
        }
        
        public void onError(Throwable error) {
        }
    });