View full sample code here
If the project has enabled Zookeeper as the registry, no additional configuration is required.
If the Zookeeper registry is not used, please refer to Add Zookeeper-related dependencies for the registry.
<dubbo:config-center address="zookeeper://127.0.0.1:2181"/>
or
dubbo
config-center
address: zookeeper://127.0.0.1:2181
or
dubbo.config-center.address=zookeeper://127.0.0.1:2181
or
ConfigCenterConfig configCenter = new ConfigCenterConfig();
configCenter.setAddress("zookeeper://127.0.0.1:2181");
For address
format, please refer to [zookeeper registry - enable configuration](../../registry/zookeeper/#22-configure and enable-zookeeper)
To enable authentication, please refer to [zookeeper registry - enable authentication](../../registry/zookeeper/#31-authentication and authentication)
1. Enable external configuration and specify key
dubbo
config-center
address: zookeeper://127.0.0.1:2181
config-file: dubbo.properties
config-file
- externalized configuration file key value, default dubbo.properties
. config-file
represents the key value corresponding to the file in the configuration center when the Dubbo configuration file is stored in the remote registration center, and it is generally not recommended to modify this configuration item.
2. Add configuration to Zookeeper configuration center The storage structure of the externalized configuration is shown in the figure below
Here is to explain the working principle, it is recommended to use dubbo-admin for configuration management.
dubbo
config-center
address: zookeeper://127.0.0.1:2181
group: dubbo-cluster1
namespace: dev1
For the configuration center, group
and namespace
should be unified across the company (cluster), avoid using different values for different applications, and external configuration and governance rules should also be stored in the corresponding group and namespace.
All traffic governance rules are stored under the /dubbo/config
node by default. The specific node structure diagram is as follows. It is recommended to add, delete, and modify traffic governance rules through dubbo-admin. For more information, please refer to the specific traffic governance capabilities supported by Dubbo