Skip to main content

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 fileModuleLocationUnified configuration centerEncryptionNotes
client-conf.xmldawdler-clientweb side {classPath}/NoNoWeb-side request configuration
dawdler-config.ymldawdler-config-centerweb side and server side {classPath}/NoNoUnified configuration center configuration
services-conf.xmldawdler-serverserver side {classPath}/NoNoService-related configuration
zookeeper.propertiesdawdler-discovery-center-zookeeper-coreweb side and server side {classPath}/YesYesRegistry configuration implemented with ZooKeeper
consul.propertiesdawdler-discovery-center-consul-coreweb side and server side {classPath}/YesYesRegistry configuration implemented with Consul
identityConfig.propertiesdawdler-client-plug-sessionweb side {classPath}/YesYesSession-related configuration
distributed-transactiondawdler-distributed-transaction-coreweb side and compensator of distributed transactions {classPath}/YesYesDistributed transaction configuration
distributed-transaction-redisdawdler-distributed-transaction-coreweb side and compensator of distributed transactions {classPath}/YesYesDistributed transaction redis configuration
distributed-transaction-rabbitmqdawdler-distributed-transaction-coreweb side and compensator of distributed transactions {classPath}/YesYesDistributed 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.