Hi,
On Mon, Apr 8, 2019 at 2:04 PM 徐靖峰 <[email protected]> wrote:
>
> Hi folks:
>
> Before Dubbo2.7 does not support the configuration center, the way to get the
> system configuration parameters is mainly through the getProperty(String key,
> String defaultValue) and getProperty(String key) methods provided by
> org.apache.dubbo.common.utils.ConfigUtils.
>
> Sample inventory code:
>
> ```java
> / / Get the logback log level
> ConfigUtils.getProperty("dubbo.logback.level");
> / / Configure the number of shared connections
> ConfigUtils.getProperty("shareconnections","1");
> ```
>
> Dubbo2.7 provides `org.apache.dubbo.common.config.ConfigurationUtils` to
> support loading configurations from multiple configuration sources.
>
> Sample inventory code:
>
> ```java
> / / Get the log4j log level
> ConfigurationUtils.getProperty("dubbo.log4j.level");
> / / Get the service outage timeout
> ConfigurationUtils.getServerShutdownTimeout()
> ```
>
> risk point:
>
> 1. After the configuration center is introduced in 2.7, you can configure the
> parameters of the application granularity in the configuration center. Some
> of the original parameters are obtained by using ConfigUtils, which may
> invalidate the user configuration.
> 2. There are different styles of obtaining application parameters in the
> inventory code. For example, the log level log4j and logback use different
> APIs.
>
> improve proposals:
>
> 1. First mark the version of ConfigUtils as expired, modify the
> implementation of ConfigUtils, and use ConfigurationUtils to bridge to
> ConfigUtils.
> 2. Avoid using ConfigUtils in future developments, avoiding directly getting
> Environment.getInstant.getConfiguration() and undoing ConfigurationUtils.
> 3. ConfigurationUtils should not contain a specific business method. It only
> provides get/set methods for configuration parameters, such as the existing
> getServerShutdownTimeout(), which should be passed in by the business
> scenario: getProperty("dubbo.server.shutdown.timeout" ).
+1 to the proposal.
>
> I will do some improvement for these risk point.
>
> ——
> 在 Dubbo2.7 未支持配置中心之前,获取系统配置参数的方式主要是通过
> org.apache.dubbo.common.utils.ConfigUtils 提供的 getProperty(String key, String
> defaultValue),getProperty(String key) 方法。
> 存量代码示例:
> // 获取 logback 日志级别
> ConfigUtils.getProperty("dubbo.logback.level");
> // 配置共享连接的数量
> ConfigUtils.getProperty("shareconnections","1");
> Dubbo2.7 提供了 org.apache.dubbo.common.config.ConfigurationUtils 支持从多种配置源中加载配置
> 存量代码示例:
> // 获取 log4j 日志级别
> ConfigurationUtils.getProperty("dubbo.log4j.level");
> // 获取服务停机超时时间
> ConfigurationUtils.getServerShutdownTimeout()
> 风险点:
> 在 2.7 推出配置中心之后,允许用户在配置中心中配置应用粒度的参数,原有的一些参数使用了 ConfigUtils 去获取,可能导致用户配置失效。
> 存量代码中多处获取应用参数的代码风格不一,如获取日志级别 log4j 和 logback 使用了不同的 api。
> 改进方案:
> 首先将就版本的 ConfigUtils 标注为过期,修改 ConfigUtils 的实现,使用 ConfigurationUtils 桥接到
> ConfigUtils。
> 今后开发中避免使用 ConfigUtils,避免直接获取 Environment.getInstant.getConfiguration(),统一走
> ConfigurationUtils。
> ConfigurationUtils 不应该包含具体某个业务方法,只提供配置参数的 get/set 方法,例如现有的
> getServerShutdownTimeout(),应当由业务场景传入键值:
> getProperty("dubbo.server.shutdown.timeout")。
>
>
>
--
Best Regards!
Huxing