You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "54hechuan (GitHub)" <gi...@apache.org> on 2018/11/07 04:34:45 UTC

[GitHub] [incubator-dubbo] 54hechuan opened pull request #2746: 解决应用通过apollo之类的配置中心来配置spring.application.name等参数时,如果应用中同时存在服务暴露(提供者)和服务消费(消费者)时,应用启动时无法读取到配置的问题

## What is the purpose of the change

解决应用通过apollo之类的配置中心来配置spring.application.name等参数时,如果应用中同时存在服务暴露(提供者)和服务消费(消费者)时,应用启动时无法读取到配置的问题

## Brief changelog

修改dubbo-config-spring 模块的
org.apache.dubbo.config.spring.context.annotation.DubboConfigBindingRegistrar.java 文件

## Verifying this change

    通读源代码发现,dubbo对于配置文件(或apollo等配置中心)中 dubbo.application.name 等配置的加载,可以通过在应用加入 @EnableDubboConfig 注解来自动加载,并初始化 ApplicationConfig 等实例。
    在应用启动的过程中,@EnableDubboConfig 注解通过 spring 的 ImportSelector 接口最终会调用 DubboConfigBindingRegistrar 类的 registerDubboConfigBean()方法 向 spring容器中注册 ApplicationConfig 、ProviderConfig、ProtocolConfig 等实例。然后在registerDubboConfigBean()方法中发现,它只是简单中向 spring容器中注入了一个配置的实例,旦没有把配置中的dubbo.application.name 等配置值设置到 ApplicationConfig等实例的相关属性中,这导致刚注入进去的ApplicationConfig实例的name等所有属性为null。通过debug代码发现,真正对些实例属性赋值的过程中延后到了初始化ReferenceConfig、ServiceConfig等实例时,通过在checkApplication()方法中调用它的抽象父类(AbstractConfig)中的appendProperties(application);来对为 ApplicationConfig 实例属性进行赋值。但如果配置不是写在配置文件而是用了 apollo等外部的配置中心时,appendProperties()方法将无法读取到这些配置,从来导致应用无法启动。
     解决这个问题的办法有好几种,最快捷的办法修改AbstractConfig类的appendProperties(),让它尝试从spring environment  加载(因为apollo将配置放了一份在spring environment 中)。还有一种办法时,在spring初始化过的过程中,把apollo等配置中心相关配置通过调用 ConfigUtils 工具类中的Properties中(appendProperties()方法就是从这里取的配置)。
    最好的解决的办法就是,在registerDubboConfigBean()方法中,ApplicationConfig 等实例刚开始注入到spring容器中时,就直接把配置中的相关配置值设值到对应实属性中。现采用这种方式参考ApplicationConfig 类的appendProperties()方法对程序进行了修改。
 

Follow this checklist to help us incorporate your contribution quickly and easily:

- [x] Make sure there is a [GITHUB_issue](https://github.com/apache/incubator-dubbo/issues) filed for the change (usually before you start working on it). Trivial changes like typos do not require a GITHUB issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
- [ ] Format the pull request title like `[Dubbo-XXX] Fix UnknownException when host config not exist #XXX`. Each commit in the pull request should have a meaningful subject line and body.
- [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [ ] Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add integration-test in [test module](https://github.com/apache/incubator-dubbo/tree/master/dubbo-test).
- [ ] Run `mvn clean install -DskipTests` & `mvn clean test-compile failsafe:integration-test` to make sure unit-test and integration-test pass.
- [ ] If this contribution is large, please follow the [Software Donation Guide](https://github.com/apache/incubator-dubbo/wiki/Software-donation-guide).


[ Full content available at: https://github.com/apache/incubator-dubbo/pull/2746 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org

[GitHub] [incubator-dubbo] dubbo-bot commented on issue #2746: 解决应用通过apollo之类的配置中心来配置spring.application.name等参数时,如果应用中同时存在服务暴露(提供者)和服务消费(消费者)时,应用启动时无法读取到配置的问题

Posted by "dubbo-bot (GitHub)" <gi...@apache.org>.
Ping @54hechuan . Conflict happens after merging a previous commit. Please rebase the branch against master and push it back again. Thanks a lot.

[ Full content available at: https://github.com/apache/incubator-dubbo/pull/2746 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org


[GitHub] [incubator-dubbo] chickenlj closed pull request #2746: 解决应用通过apollo之类的配置中心来配置spring.application.name等参数时,如果应用中同时存在服务暴露(提供者)和服务消费(消费者)时,应用启动时无法读取到配置的问题

Posted by "chickenlj (GitHub)" <gi...@apache.org>.
[ pull request closed by chickenlj ]

[ Full content available at: https://github.com/apache/incubator-dubbo/pull/2746 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org


[GitHub] [incubator-dubbo] chickenlj commented on issue #2746: 解决应用通过apollo之类的配置中心来配置spring.application.name等参数时,如果应用中同时存在服务暴露(提供者)和服务消费(消费者)时,应用启动时无法读取到配置的问题

Posted by "chickenlj (GitHub)" <gi...@apache.org>.
I think the new [Config Center](https://github.com/apache/incubator-dubbo/issues/2916) concept introduced in 2.7.0 can solve your problem here. 

Feel free to reopen if you have different opinions.

[ Full content available at: https://github.com/apache/incubator-dubbo/pull/2746 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org


[GitHub] [incubator-dubbo] dubbo-bot commented on issue #2746: 解决应用通过apollo之类的配置中心来配置spring.application.name等参数时,如果应用中同时存在服务暴露(提供者)和服务消费(消费者)时,应用启动时无法读取到配置的问题

Posted by "dubbo-bot (GitHub)" <gi...@apache.org>.
Ping @54hechuan . Conflict happens after merging a previous commit. Please rebase the branch against master and push it back again. Thanks a lot.

[ Full content available at: https://github.com/apache/incubator-dubbo/pull/2746 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org


[GitHub] [incubator-dubbo] codecov-io commented on issue #2746: 解决应用通过apollo之类的配置中心来配置spring.application.name等参数时,如果应用中同时存在服务暴露(提供者)和服务消费(消费者)时,应用启动时无法读取到配置的问题

Posted by "codecov-io (GitHub)" <gi...@apache.org>.
# [Codecov](https://codecov.io/gh/apache/incubator-dubbo/pull/2746?src=pr&el=h1) Report
> Merging [#2746](https://codecov.io/gh/apache/incubator-dubbo/pull/2746?src=pr&el=desc) into [master](https://codecov.io/gh/apache/incubator-dubbo/commit/56b219316205a12b4ce95a82b10b527798df9e34?src=pr&el=desc) will **decrease** coverage by `0.03%`.
> The diff coverage is `53.57%`.

[![Impacted file tree graph](https://codecov.io/gh/apache/incubator-dubbo/pull/2746/graphs/tree.svg?width=650&token=VnEIkiFQT0&height=150&src=pr)](https://codecov.io/gh/apache/incubator-dubbo/pull/2746?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #2746      +/-   ##
==========================================
- Coverage   63.49%   63.45%   -0.04%     
==========================================
  Files         577      577              
  Lines       25923    25960      +37     
  Branches     4541     4554      +13     
==========================================
+ Hits        16459    16474      +15     
- Misses       7301     7320      +19     
- Partials     2163     2166       +3
```


| [Impacted Files](https://codecov.io/gh/apache/incubator-dubbo/pull/2746?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [...n/java/org/apache/dubbo/config/AbstractConfig.java](https://codecov.io/gh/apache/incubator-dubbo/pull/2746/diff?src=pr&el=tree#diff-ZHViYm8tY29uZmlnL2R1YmJvLWNvbmZpZy1hcGkvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2R1YmJvL2NvbmZpZy9BYnN0cmFjdENvbmZpZy5qYXZh) | `74.34% <ø> (+0.65%)` | :arrow_up: |
| [...ontext/annotation/DubboConfigBindingRegistrar.java](https://codecov.io/gh/apache/incubator-dubbo/pull/2746/diff?src=pr&el=tree#diff-ZHViYm8tY29uZmlnL2R1YmJvLWNvbmZpZy1zcHJpbmcvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2R1YmJvL2NvbmZpZy9zcHJpbmcvY29udGV4dC9hbm5vdGF0aW9uL0R1YmJvQ29uZmlnQmluZGluZ1JlZ2lzdHJhci5qYXZh) | `79.26% <53.57%> (-13.46%)` | :arrow_down: |
| [...ache/dubbo/remoting/transport/AbstractChannel.java](https://codecov.io/gh/apache/incubator-dubbo/pull/2746/diff?src=pr&el=tree#diff-ZHViYm8tcmVtb3RpbmcvZHViYm8tcmVtb3RpbmctYXBpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9kdWJiby9yZW1vdGluZy90cmFuc3BvcnQvQWJzdHJhY3RDaGFubmVsLmphdmE=) | `37.5% <0%> (-50%)` | :arrow_down: |
| [...che/dubbo/remoting/transport/mina/MinaChannel.java](https://codecov.io/gh/apache/incubator-dubbo/pull/2746/diff?src=pr&el=tree#diff-ZHViYm8tcmVtb3RpbmcvZHViYm8tcmVtb3RpbmctbWluYS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZHViYm8vcmVtb3RpbmcvdHJhbnNwb3J0L21pbmEvTWluYUNoYW5uZWwuamF2YQ==) | `39.47% <0%> (-10.53%)` | :arrow_down: |
| [.../org/apache/dubbo/config/AbstractMethodConfig.java](https://codecov.io/gh/apache/incubator-dubbo/pull/2746/diff?src=pr&el=tree#diff-ZHViYm8tY29uZmlnL2R1YmJvLWNvbmZpZy1hcGkvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2R1YmJvL2NvbmZpZy9BYnN0cmFjdE1ldGhvZENvbmZpZy5qYXZh) | `94% <0%> (-6%)` | :arrow_down: |
| [.../apache/dubbo/qos/protocol/QosProtocolWrapper.java](https://codecov.io/gh/apache/incubator-dubbo/pull/2746/diff?src=pr&el=tree#diff-ZHViYm8tcGx1Z2luL2R1YmJvLXFvcy9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZHViYm8vcW9zL3Byb3RvY29sL1Fvc1Byb3RvY29sV3JhcHBlci5qYXZh) | `65.78% <0%> (-5.27%)` | :arrow_down: |
| [...onfig/spring/extension/SpringExtensionFactory.java](https://codecov.io/gh/apache/incubator-dubbo/pull/2746/diff?src=pr&el=tree#diff-ZHViYm8tY29uZmlnL2R1YmJvLWNvbmZpZy1zcHJpbmcvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2R1YmJvL2NvbmZpZy9zcHJpbmcvZXh0ZW5zaW9uL1NwcmluZ0V4dGVuc2lvbkZhY3RvcnkuamF2YQ==) | `78.94% <0%> (-5.27%)` | :arrow_down: |
| [...ubbo/rpc/protocol/dubbo/ChannelWrappedInvoker.java](https://codecov.io/gh/apache/incubator-dubbo/pull/2746/diff?src=pr&el=tree#diff-ZHViYm8tcnBjL2R1YmJvLXJwYy1kdWJiby9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZHViYm8vcnBjL3Byb3RvY29sL2R1YmJvL0NoYW5uZWxXcmFwcGVkSW52b2tlci5qYXZh) | `37.5% <0%> (-4.17%)` | :arrow_down: |
| [...c/main/java/org/apache/dubbo/rpc/RpcException.java](https://codecov.io/gh/apache/incubator-dubbo/pull/2746/diff?src=pr&el=tree#diff-ZHViYm8tcnBjL2R1YmJvLXJwYy1hcGkvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2R1YmJvL3JwYy9ScGNFeGNlcHRpb24uamF2YQ==) | `85.71% <0%> (-3.58%)` | :arrow_down: |
| [...g/apache/dubbo/config/AbstractInterfaceConfig.java](https://codecov.io/gh/apache/incubator-dubbo/pull/2746/diff?src=pr&el=tree#diff-ZHViYm8tY29uZmlnL2R1YmJvLWNvbmZpZy1hcGkvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2R1YmJvL2NvbmZpZy9BYnN0cmFjdEludGVyZmFjZUNvbmZpZy5qYXZh) | `78.44% <0%> (-2.34%)` | :arrow_down: |
| ... and [9 more](https://codecov.io/gh/apache/incubator-dubbo/pull/2746/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/apache/incubator-dubbo/pull/2746?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/apache/incubator-dubbo/pull/2746?src=pr&el=footer). Last update [56b2193...fedcfdc](https://codecov.io/gh/apache/incubator-dubbo/pull/2746?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


[ Full content available at: https://github.com/apache/incubator-dubbo/pull/2746 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org

[GitHub] [incubator-dubbo] dubbo-bot commented on issue #2746: 解决应用通过apollo之类的配置中心来配置spring.application.name等参数时,如果应用中同时存在服务暴露(提供者)和服务消费(消费者)时,应用启动时无法读取到配置的问题

Posted by "dubbo-bot (GitHub)" <gi...@apache.org>.
Ping @54hechuan . Conflict happens after merging a previous commit. Please rebase the branch against master and push it back again. Thanks a lot.

[ Full content available at: https://github.com/apache/incubator-dubbo/pull/2746 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org


[GitHub] [incubator-dubbo] dubbo-bot commented on issue #2746: 解决应用通过apollo之类的配置中心来配置spring.application.name等参数时,如果应用中同时存在服务暴露(提供者)和服务消费(消费者)时,应用启动时无法读取到配置的问题

Posted by "dubbo-bot (GitHub)" <gi...@apache.org>.
Ping @54hechuan . Conflict happens after merging a previous commit. Please rebase the branch against master and push it back again. Thanks a lot.

[ Full content available at: https://github.com/apache/incubator-dubbo/pull/2746 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org


[GitHub] [incubator-dubbo] carryxyh commented on issue #2746: 解决应用通过apollo之类的配置中心来配置spring.application.name等参数时,如果应用中同时存在服务暴露(提供者)和服务消费(消费者)时,应用启动时无法读取到配置的问题

Posted by "carryxyh (GitHub)" <gi...@apache.org>.
Seems like your pr can not pass the ci check.
Pls solve it first.

[ Full content available at: https://github.com/apache/incubator-dubbo/pull/2746 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org


[GitHub] [incubator-dubbo] dubbo-bot commented on issue #2746: 解决应用通过apollo之类的配置中心来配置spring.application.name等参数时,如果应用中同时存在服务暴露(提供者)和服务消费(消费者)时,应用启动时无法读取到配置的问题

Posted by "dubbo-bot (GitHub)" <gi...@apache.org>.
Ping @54hechuan . Conflict happens after merging a previous commit. Please rebase the branch against master and push it back again. Thanks a lot.

[ Full content available at: https://github.com/apache/incubator-dubbo/pull/2746 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org