-
Notifications
You must be signed in to change notification settings - Fork 393
22 config center
Alpha Yu edited this page Apr 26, 2026
·
1 revision
ADNC supports two modes for loading configurations:
-
File: Reads from local
appsettingsfiles (default for local development). - Consul: Reads from Consul Key-Value (KV) store (recommended for Staging/Production).
- Start Consul.
- Add configurations to Consul KV (typically a shared config and a service-specific config).
- Set
ConfigurationTypetoConsulin your service'sappsettings.json. - Configure
ConsulUrlandConsulKeyPath. - Start the service. Configurations are refreshed automatically (polling).
When a service starts, it calls AddConfiguration:
-
File Mode: Loads
appsettings.shared.{Environment}.jsonfrom the execution directory. -
Consul Mode: Connects to
ConsulUrland loads the keys specified inConsulKeyPath. -
Placeholder Replacement: After loading, the system automatically replaces placeholders like
$SERVICENAME,$SHORTNAME, and$RELATIVEROOTPATH.
Example configuration for a Staging environment:
{
"ConfigurationType": "Consul",
"Consul": {
"ConsulUrl": "http://172.80.0.4:8500",
"ConsulKeyPath": "adnc/staging/shared/appsettings,adnc/staging/$SHORTNAME/appsettings"
}
}- ConsulUrl: The HTTP API address of your Consul instance.
- ConsulKeyPath: Comma-separated paths to KV keys. They are loaded in order.
-
$SHORTNAME: Automatically replaced with the service's short name (e.g.,
cust-api).
We recommend a two-layer configuration strategy:
-
Shared Config (
adnc/{env}/shared/appsettings): Contains common settings like Redis, RabbitMQ, Polly, and SkyWalking. -
Service-Specific Config (
adnc/{env}/{shortName}/appsettings): Overrides or adds settings specific to that service (e.g., DB connection strings).
The KV values should be valid JSON strings.
When using Consul, ADNC enables reloadOnChanges=true. The Consul provider polls the KV store every 3 seconds. If the LastIndex changes, the configuration is reloaded and placeholders are re-processed.
Note: While configurations reload, some components that cache settings on startup may still require a restart to reflect changes.
The repository includes scripts to initialize a Demo environment:
-
Scripts:
doc/devops-staging/adnc-consul/consul-init.sh -
Initial Data:
doc/devops-staging/adnc-consul/kv.json
If this helps, please Star & Fork.
- Official Website: https://aspdotnetcore.net
- Online Demo: https://online.aspdotnetcore.net
- Documentation: https://docs.aspdotnetcore.net
- Code Generator: https://code.aspdotnetcore.net