Multi-Environment Configuration
1. Usage
Pass dawdler.profiles.active as a JVM parameter For example:
-Ddawdler.profiles.active=uat
The command above selects the configuration files for the uat environment.
2. Loading order
If the deployed project contains a dawdler.profiles.active setting, it is loaded first.
For example:
If the project contains the two configuration files session-redis.properties and session-redis-uat.properties, and the startup parameter sets -Ddawdler.profiles.active=uat, then session-redis-uat.properties is loaded.
Local configuration files take precedence over configuration from the unified configuration center.
3. Multi-environment configuration of dawdler.* system properties
The properties: section of dawdler-config.yml carries the framework's own dawdler.* system properties (which are otherwise only supported via -D). This section also supports multi-environment profiles (dawdler-config-uat.yml), fallback to the unified configuration center, ${} variable substitution and ENC() encryption.
# dawdler-config.yml
snapshot-id: my-app
consul:
host: 127.0.0.1
properties:
dawdler.max.frame.length: 16777216
dawdler.server.metrics.enabled: true
Priority: -D > environment variables (e.g. DAWDLER_MAX_FRAME_LENGTH) > the properties: section of dawdler-config.yml > default values.
For all configuration keys, default values and read timing see dawdler-config-README.md.
4. List of supported component configuration files
| Configuration file | Module | Location | Unified configuration center | Encryption | Notes |
|---|---|---|---|---|---|
| client-conf.xml | dawdler-client | web side {classPath}/ | No | No | Web-side request configuration |
| dawdler-config.yml | dawdler-config-center | web side and server side {classPath}/ | No | No | Unified configuration center configuration |
| services-conf.xml | dawdler-server | server side {classPath}/ | No | No | Service-related configuration |
| zookeeper.properties | dawdler-discovery-center-zookeeper-core | web side and server side {classPath}/ | Yes | Yes | Registry configuration implemented with ZooKeeper |
| consul.properties | dawdler-discovery-center-consul-core | web side and server side {classPath}/ | Yes | Yes | Registry configuration implemented with Consul |
| identityConfig.properties | dawdler-client-plug-session | web side {classPath}/ | Yes | Yes | Session-related configuration |
| distributed-transaction | dawdler-distributed-transaction-core | web side and compensator of distributed transactions {classPath}/ | Yes | Yes | Distributed transaction configuration |
| distributed-transaction-redis | dawdler-distributed-transaction-core | web side and compensator of distributed transactions {classPath}/ | Yes | Yes | Distributed transaction redis configuration |
| distributed-transaction-rabbitmq | dawdler-distributed-transaction-core | web side and compensator of distributed transactions {classPath}/ | Yes | Yes | Distributed transaction rabbitmq configuration |
5. Configuration of other components
Every component configuration implemented in the system supports multi-environment configuration, the unified configuration center, encryption and variable substitution.
For example redis, es, rabbitmq and kafka.
public class UserServiceImpl implements UserService {
@EsInjector("myEs")
EsOperator esOperator;
@RabbitInjector("myRabbit")
RabbitProvider rabbitProvider;
@JedisInjector("myJedis")
JedisOperator jedisOperator;
@KafkaInjector("myKafka")
KafkaProvider kafkaProvider;
}
6. Variable substitution
Variable substitution is supported in all xml, properties and yml files and in the unified configuration center.
Take yml as an example:
name: "${app.name}"
port: 9090
url: "${API_URL:http://localhost:3000}"
description: "This is ${app.name:DefaultApp} running on port 9090"
The priority of variable substitution is System.getProperty > System.getenv.
In the example, ${app.name} is first taken from System.getProperty("app.name"); if it is not found, it is taken from System.getenv("app.name"); if it is still not found, the value is ${app.name}.
In the example, ${API_URL:http://localhost:3000} is first taken from System.getProperty("API_URL"); if it is not found, it is taken from System.getenv("API_URL"); if it is still not found, the value is http://localhost:3000.