View the complete example code
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>3.0.9</version>
</dependency>
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-openapi</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
<version>2.0.0</version>
</dependency>
<dubbo:config-center address="apollo://localhost:8080"/>
or
dubbo
config-center
address: apollo://localhost:8080
or
dubbo.config-center.address=apollo://localhost:8080
or
ConfigCenterConfig configCenter = new ConfigCenterConfig();
configCenter.setAddress("apollo://localhost:8080");
A core concept in Apollo is the namespace, which is different from the namespace concepts of Zookeeper and Nacos. Therefore, the usage is somewhat special; it is recommended to fully understand Apollo’s usage before reading the following document content.
Generally speaking, for adaptation to Apollo:
<dubbo:config-center group="demo-provider" address="apollo://localhost:8080"/>
The group
of config-center determines the location of the externalized configuration dubbo.properties
file in Apollo:
dubbo
namespace, and users must write externalized configurations under the dubbo
namespace.For example, the following example uses the default group=‘dubbo’ for global externalized configuration, meaning this configuration can be read by all applications.
If the group is set to ‘application name’, then it is application-specific configuration, and only that application can read it.
The external file configuration hosting means that the contents of the
dubbo.properties
configuration file are stored in Apollo. Each application can inherit common configurations through the associated shareddubbo
namespace and can individually override specific configuration items.
Traffic governance rules are globally shared, so the namespace configurations within each application should remain consistent.
<dubbo:config-center namespace="governance" address="apollo://localhost:8080"/>
The namespace
of config-center determines the location of the traffic governance rules in Apollo:
dubbo
namespace, and governance rules must be written under the dubbo
namespace.For example, the following example uses namespace='governance'
to place traffic governance rules in the governance
namespace.
Currently, Dubbo has adapted specific configuration items such as env, apollo.meta, apollo.cluster, and apollo.id, which can be configured via the extension parameters of config-center.
For example,
dubbo.config-center.address=apollo://localhost:8080
or
dubbo.config-center.parameters.apollo.meta=xxx
dubbo.config-center.parameters.env=xxx