revoke-config
Configuration management module for the Revoke microservices framework, supporting multiple backend stores and real-time configuration watching.
Features
- Multiple Backends: Memory, file, and Consul backends, enabled via feature flags
- Format Auto-detection: Automatically detects and parses JSON, YAML, and TOML files
- Real-time Watching: Watch configuration changes through streaming updates
- Version Tracking: Built-in configuration change version tracking
- Metadata Support: Attach metadata to configuration items (creation time, update time, tags, etc.)
- Type Safety: Strongly typed configuration values using serde serialization
- Async Support: Fully async API based on Tokio
Installation
Add to your Cargo.toml:
[]
= { = "0.1", = ["memory", "file", "consul"] }
Feature Flags
memory(default): In-memory configuration providerfile: File-based configuration with auto-reload supportconsul: Consul KV store integrationetcd: etcd integration (requires protoc)full: Enable all features
Usage
Memory Provider
Simple in-memory configuration storage:
use MemoryConfigProvider;
use ConfigProvider;
async
With initial values:
use HashMap;
use json;
let mut initial = new;
initial.insert;
initial.insert;
let provider = with_initial_values;
File Provider
File-based configuration with automatic format detection:
use FileConfigProvider;
use ConfigProvider;
async
Enable file watching (requires notify feature):
Consul Provider
Integration with Consul KV store:
use ;
use ConfigProvider;
use Duration;
async
Configuration Watching
Watch for real-time configuration changes:
use StreamExt;
use ConfigProvider;
let mut stream = provider.watch.await?;
spawn;
Configuration Formats
The file provider supports multiple formats:
JSON:
YAML:
app:
name: my-service
port: 8080
TOML:
[]
= "my-service"
= 8080
Advanced Usage
Custom Configuration Listener
use ConfigWatcher;
use Arc;
let watcher = new;
// Subscribe to changes
watcher.subscribe;
// Notify changes
watcher.notify;
Configuration Metadata
use ;
use Utc;
let value = ConfigValue ;
Configuration Validation
use ;
use ConfigValidator;
// Validate configuration
let json_value = provider.get.await?;
let config: AppConfig = from_str?;
if config.port < 1024
Best Practices
- Namespace Configuration: Use dot notation for hierarchical configuration
- Watch Granularity: Watch specific keys rather than entire configuration
- Error Handling: Always handle configuration missing or parsing errors
- Caching: Providers include built-in caching for performance
- Atomic Updates: Use transactions when updating multiple related values
Performance Considerations
- Memory Provider: O(1) lookups, suitable for frequently accessed configuration
- File Provider: Cached in memory, file I/O only on changes
- Consul Provider: Network calls with local caching, configurable refresh interval
Error Handling
All providers return Result<T, RevokeError> with specific error types:
match provider.get.await
Security
- Sensitive Data: Use encryption for sensitive configuration values
- Access Control: Consul provider supports ACL tokens
- Audit Trail: Metadata tracks who changed configuration
- Environment Variables: Support for environment variable substitution
Examples
See the examples directory for complete examples:
memory_provider.rs- Basic memory configurationfile_provider.rs- File-based configuration with watchingconsul_provider.rs- Consul integrationconfig_validation.rs- Configuration validation patterns