View the complete sample code
If the project has already enabled Zookeeper as the registry, no additional configurations are necessary.
If Zookeeper is not used as the registry, 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 the format of address
, refer to zookeeper registry - enable configuration
To enable authentication and authorization, refer to zookeeper registry - enable authentication and authorization
1. Enable externalized configuration and specify key
dubbo
config-center
address: zookeeper://127.0.0.1:2181
config-file: dubbo.properties
config-file
- key value of the externalized configuration file, default dubbo.properties
. config-file
represents the key value corresponding to the Dubbo configuration file when stored in the remote registry, and it is generally not recommended to change this configuration item.
2. Add configuration to Zookeeper Configuration Center The storage structure of externalized configuration is shown in the diagram below.
This is to illustrate 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), and different applications should avoid using different values. Externalized configurations and governance rules should also be stored under the corresponding group and namespace.
All traffic governance rules are by default stored under the /dubbo/config
node. The specific node structure diagram is as follows. It is recommended to use dubbo-control-plane (dubbo-admin) for adding, deleting, or modifying traffic governance rules. More content can be found in Dubbo’s supported traffic governance capabilities.