The following is an example of Dubbo property configuration dubbo-spring-boot-samples
## application.properties
# Spring boot application
spring.application.name=dubbo-externalized-configuration-provider-sample
# Base packages to scan Dubbo Component: @com.alibaba.dubbo.config.annotation.Service
dubbo.scan.base-packages=com.alibaba.boot.dubbo.demo.provider.service
# Dubbo Application
## The default value of dubbo.application.name is ${spring.application.name}
## dubbo.application.name=${spring.application.name}
#Dubbo Protocol
dubbo.protocol.name=dubbo
dubbo.protocol.port=12345
## Dubbo Registry
dubbo.registry.address=N/A
## service default version
dubbo.provider.version=1.0.0
Next, around this example, we analyze the working principle of Dubbo configuration from three aspects: configuration format, configuration source, and loading process.
All configurations currently supported by Dubbo are in .properties
format, including -D
, Externalized Configuration
, etc. All configuration items in .properties
follow a path-based
configuration format.
In the Spring application, you can also put the attribute configuration in application.yml
, and the tree hierarchy is more readable.
# Application-level configuration (no id)
dubbo.{config-type}.{config-item}={config-item-value}
# Instance-level configuration (specify id or name)
dubbo.{config-type}s.{config-id}.{config-item}={config-item-value}
dubbo.{config-type}s.{config-name}.{config-item}={config-item-value}
# Service interface configuration
dubbo.service.{interface-name}.{config-item}={config-item-value}
dubbo.reference.{interface-name}.{config-item}={config-item-value}
# method configuration
dubbo.service.{interface-name}.{method-name}.{config-item}={config-item-value}
dubbo.reference.{interface-name}.{method-name}.{config-item}={config-item-value}
# Method argument configuration
dubbo.reference.{interface-name}.{method-name}.{argument-index}.{config-item}={config-item-value}
The format of application-level configuration is: configuration type singular prefix, no id/name.
# Application-level configuration (no id)
dubbo.{config-type}.{config-item}={config-item-value}
Similar to application
, monitor
, metrics
, etc. are all application-level components, so only a single instance is allowed to be configured; while protocol
, registry
, etc. allow to configure multiple components, when only singleton configuration is required , in the format described in this section. Common examples are as follows:
dubbo.application.name=demo-provider
dubbo.application.qos-enable=false
dubbo.registry.address=zookeeper://127.0.0.1:2181
dubbo.protocol.name=dubbo
dubbo.protocol.port=-1
The attribute configuration for an instance needs to specify an id or name, and its prefix format is: configuration type plural prefix + id/name. Applicable to protocol
, registry
and other components that support multiple configurations.
# Instance-level configuration (specify id or name)
dubbo.{config-type}s.{config-id}.{config-item}={config-item-value}
dubbo.{config-type}s.{config-name}.{config-item}={config-item-value}
Configuration example:
dubbo.registries.unit1.address=zookeeper://127.0.0.1:2181
dubbo.registries.unit2.address=zookeeper://127.0.0.1:2182
dubbo.protocols.dubbo.name=dubbo
dubbo.protocols.dubbo.port=20880
dubbo.protocols.hessian.name=hessian
dubbo.protocols.hessian.port=8089
dubbo.service.org.apache.dubbo.samples.api.DemoService.timeout=5000
dubbo.reference.org.apache.dubbo.samples.api.DemoService.timeout=6000
Method configuration format:
# method configuration
dubbo.service.{interface-name}.{method-name}.{config-item}={config-item-value}
dubbo.reference.{interface-name}.{method-name}.{config-item}={config-item-value}
# Method argument configuration
dubbo.reference.{interface-name}.{method-name}.{argument-index}.{config-item}={config-item-value}
Example method configuration:
dubbo.reference.org.apache.dubbo.samples.api.DemoService.sayHello.timeout=7000
dubbo.reference.org.apache.dubbo.samples.api.DemoService.sayHello.oninvoke=notifyService.onInvoke
dubbo.reference.org.apache.dubbo.samples.api.DemoService.sayHello.onreturn=notifyService.onReturn
dubbo.reference.org.apache.dubbo.samples.api.DemoService.sayHello.onthrow=notifyService.onThrow
dubbo.reference.org.apache.dubbo.samples.api.DemoService.sayHello.0.callback=true
Equivalent to XML configuration:
<dubbo:reference interface="org.apache.dubbo.samples.api.DemoService">
<dubbo:method name="sayHello" timeout="7000" oninvoke="notifyService.onInvoke"
onreturn="notifyService.onReturn" onthrow="notifyService.onThrow">
<dubbo:argument index="0" callback="true" />
</dubbo:method>
</dubbo:reference>
The parameters parameter is a map object, which supports configuration in the form of xxx.parameters=[{key:value},{key:value}].
dubbo.application.parameters=[{item1:value1},{item2:value2}]
dubbo.reference.org.apache.dubbo.samples.api.DemoService.parameters=[{item3:value3}]
The triple protocol uses Http2 as the underlying communication protocol, allowing users to customize [6 settings parameters] of Http2 (https://datatracker.ietf.org/doc/html/rfc7540#section-6.5.2)
The configuration format is as follows:
# Notify the peer header of the upper limit of compressed index tables
dubbo.rpc.tri.header-table-size=4096
# Enable server-side push function
dubbo.rpc.tri.enable-push=false
# Notify the peer of the maximum number of concurrent streams allowed
dubbo.rpc.tri.max-concurrent-streams=2147483647
# Declare the window size of the sender
dubbo.rpc.tri.initial-window-size=1048576
# Set the maximum number of bytes for the frame
dubbo.rpc.tri.max-frame-size=32768
# Notify the peer of the maximum number of uncompressed bytes in the header
dubbo.rpc.tri.max-header-list-size=8192
Equivalent to yml configuration:
dubbo:
rpc:
tri:
header-table-size: 4096
enable-push: false
max-concurrent-streams: 2147483647
initial-window-size: 1048576
max-frame-size: 32768
max-header-list-size: 8192
The xml tag name and attribute name can be combined, separated by ‘.’. One attribute per line.
dubbo.application.name=foo
is equivalent to <dubbo:application name="foo" />
dubbo.registry.address=10.20.153.10:9090
is equivalent to <dubbo:registry address="10.20.153.10:9090" />
If there is more than one tag in xml configuration, then you can use ‘id’ to differentiate. If you don’t specify an id, it will apply to all tags.
dubbo.protocols.rmi.port=1099
is equivalent to <dubbo:protocol id="rmi" name="rmi" port="1099" />
dubbo.registries.china.address=10.20.153.10:9090
is equivalent to <dubbo:registry id="china" address="10.20.153.10:9090" />
Plural configurations are named in the same way as regular words are pluralized:
| Config Type | Singular Configuration | Plural Configuration |
| ———————————— | ————— ———————————————— | —- ———————————- |
| application | dubbo.application.xxx=xxx | dubbo.applications.{id}.xxx=xxx
dubbo.applications.{name}.xxx=xxx |
| protocol | dubbo.protocol.xxx=xxx | dubbo.protocols.{id}.xxx=xxx
dubbo.protocols.{name}.xxx=xxx |
| module | dubbo.module.xxx=xxx | dubbo.modules.{id}.xxx=xxx
dubbo.modules.{name}.xxx=xxx |
| registry | dubbo.registry.xxx=xxx | dubbo.registries.{id}.xxx=xxx |
| monitor | dubbo.monitor.xxx=xxx | dubbo.monitors.{id}.xxx=xxx |
| config-center | dubbo.config-center.xxx=xxx | dubbo.config-centers.{id}.xxx=xxx |
| metadata-report | dubbo.metadata-report.xxx=xxx | dubbo.metadata-reports.{id}.xxx=xxx |
| ssl | dubbo.ssl.xxx=xxx | dubbo.ssls.{id}.xxx=xxx |
| metrics | dubbo.metrics.xxx=xxx | dubbo.metricses.{id}.xxx=xxx |
| provider | dubbo.provider.xxx=xxx | dubbo.providers.{id}.xxx=xxx |
| consumer | dubbo.consumer.xxx=xxx | dubbo.consumers.{id}.xxx=xxx |
| service | dubbo.service.{interfaceName}.xxx=xxx | None |
| reference | dubbo.reference.{interfaceName}.xxx=xxx | None |
| method | dubbo.service.{interfaceName}.{methodName}.xxx=xxx
dubbo.reference.{interfaceName}.{methodName}.xxx=xxx | None |
| argument | dubbo.service.{interfaceName}.{methodName}.{arg-index}.xxx=xxx | None |
Dubbo supports 6 configuration sources by default:
About the dubbo.properties attribute:
-Ddubbo.properties.file=xxx.properties
.If the same configuration item is specified through multiple configuration sources, configuration items will overlap each other. Please refer to the next section for specific coverage relationship and priority.
Dubbo configuration loading is roughly divided into two stages:
There may be two situations where property overriding occurs, and the two may occur at the same time:
Property override refers to overriding the properties of the config bean instance with the configured property values, similar to Spring [PropertyOverrideConfigurer](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/beans/ factory/config/PropertyOverrideConfigurer.html) .
Property resource configurer that overrides bean property values in an application context definition. It pushes values from a properties file into bean definitions. Configuration lines are expected to be of the following form:
beanName.property=value
But the difference from PropertyOverrideConfigurer
is that Dubbo’s property override has multiple matching formats, and the priority from high to low is:
#1. Instance-level configuration of the specified id
dubbo.{config-type}s.{config-id}.{config-item}={config-item-value}
#2. Specify the instance-level configuration of the name
dubbo.{config-type}s.{config-name}.{config-item}={config-item-value}
#3. Application-level configuration (singular configuration)
dubbo.{config-type}.{config-item}={config-item-value}
Attribute override processing flow:
Search in order of priority from high to low. If an attribute starting with this prefix is found, use this prefix to extract the attribute and ignore the subsequent configuration.
One of the purposes of external configuration is to achieve centralized management of configuration. There are already many mature professional configuration systems in this part of the industry, such as Apollo, Nacos, etc. What Dubbo does is mainly to ensure that it can work with these systems.
There is no difference in content and format between externalized configuration and other local configurations. It can be simply understood as the externalized storage of dubbo.properties
. The configuration center is more suitable for extracting some public configurations such as registration centers and metadata center configurations for future use. centralized management.
# Centralized management of registration center address, metadata center address and other configurations can achieve a unified environment and reduce development-side perception.
dubbo.registry.address=zookeeper://127.0.0.1:2181
dubbo.registry.simplified=true
dubbo.metadata-report.address=zookeeper://127.0.0.1:2181
dubbo.protocol.name=dubbo
dubbo.protocol.port=20880
dubbo.application.qos.port=33333
priority By default, the externalized configuration has a higher priority than the local configuration, so the content configured here will override the local configuration value. There is a separate chapter explaining the [Override Relationship] (#21-Override Relationship) between various configuration forms.
scope There are two levels of external configuration: global and application. The global configuration is shared by all applications. The application-level configuration is maintained by each application and is only visible to itself. Currently supported extensions include Zookeeper, Apollo, and Nacos.
<dubbo:config-center address="zookeeper://127.0.0.1:2181"/>
After the external configuration is enabled, global configurations such as registry, metadata-report, protocol, and qos theoretically no longer need to be configured in the application. The application development side focuses on business service configuration, and some globally shared global configurations are transferred to O&M. The personnel are uniformly configured in the remote configuration center.
The effect of this is that the application only needs to care about:
For example, only the following Dubbo-related configurations in each application may be sufficient, and the rest are hosted in the configuration center in the corresponding environment:
dubbo
application
name: demo
config-center
address: nacos://127.0.0.1:8848
The so-called Dubbo’s support for the configuration center is essentially to pull .properties
from the remote to the local, and then integrate it with the local configuration. In theory, as long as the Dubbo framework can get the required configuration, it can start normally. It doesn’t care whether these configurations are loaded by itself or directly inserted by the application, so Dubbo also provides the following APIs to allow users to organize themselves. The configuration is stuffed into the Dubbo framework (the configuration loading process is to be completed by the user), so that the Dubbo framework no longer directly interacts with Apollo or Zookeeper to read the configuration.
// The application loads its own configuration
Map<String, String> dubboConfigurations = new HashMap<>();
dubboConfigurations.put("dubbo.registry.address", "zookeeper://127.0.0.1:2181");
dubboConfigurations.put("dubbo.registry.simplified", "true");
//Throw the organized configuration into the Dubbo framework
ConfigCenterConfig configCenter = new ConfigCenterConfig();
configCenter.setExternalConfig(dubboConfigurations);