Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dubbo 2.7.8 整合Apollo配置中心,在指定外部配置的情况下,无法获取正确的Namespace,应用启动失败 #6606

Closed
1 of 2 tasks
pengshaoxing opened this issue Aug 16, 2020 · 2 comments

Comments

@pengshaoxing
Copy link

pengshaoxing commented Aug 16, 2020

  • I have searched the issues of this repository and believe that this is not a duplicate.
  • I have checked the FAQ of this repository and believe that this is not a duplicate.

Environment

  • Dubbo version: 2.7.8
  • Operating System version: WINDOWS 10 20H1
  • Java version: Java 1.8

Steps to reproduce this issue

  1. 配置文件中指定apollo配置中心的相关值。
dubbo:
  config-center:
    address: apollo://t.ppssxx.com:8080
    # 配置中心的配置覆盖本地配置
    highest-priority: true
    namespace: TEST1.dubbo
    config-file: TEST1.dubbo.properties
    group: TEST1.dubbo
    app-config-file: TEST1.dubbo.properties
  1. 启动应用,拉取配置
  2. 应用启动失败

Pls. provide [GitHub address] to reproduce this issue.

Expected Result

What do you expected from the above steps?

应该正确获取到配置文件中指定的Namespace值,在本场景中为TEST1.dubbo

Actual Result

未能正确获取,而是变成了默认的dubbo
What actually happens?

If there is an exception, please attach the exception trace:

2020-08-16 23:34:37.645 ERROR 3752 --- [           main] o.s.boot.SpringApplication               : Application run failed

java.lang.IllegalStateException: Failed to connect to config center, the config center is Apollo, the address is: http://xxx:8080
	at org.apache.dubbo.configcenter.support.apollo.ApolloDynamicConfiguration.<init>(ApolloDynamicConfiguration.java:109) ~[dubbo-2.7.8.jar:2.7.8]
	at org.apache.dubbo.configcenter.support.apollo.ApolloDynamicConfigurationFactory.createDynamicConfiguration(ApolloDynamicConfigurationFactory.java:29) ~[dubbo-2.7.8.jar:2.7.8]
	at org.apache.dubbo.common.config.configcenter.AbstractDynamicConfigurationFactory.lambda$getDynamicConfiguration$0(AbstractDynamicConfigurationFactory.java:39) ~[dubbo-2.7.8.jar:2.7.8]
	at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708) ~[na:na]
	at org.apache.dubbo.common.config.configcenter.AbstractDynamicConfigurationFactory.getDynamicConfiguration(AbstractDynamicConfigurationFactory.java:39) ~[dubbo-2.7.8.jar:2.7.8]
	at org.apache.dubbo.common.config.configcenter.DynamicConfiguration.getDynamicConfiguration(DynamicConfiguration.java:224) ~[dubbo-2.7.8.jar:2.7.8]
	at org.apache.dubbo.config.bootstrap.DubboBootstrap.prepareEnvironment(DubboBootstrap.java:1034) ~[dubbo-2.7.8.jar:2.7.8]
	at org.apache.dubbo.config.bootstrap.DubboBootstrap.startConfigCenter(DubboBootstrap.java:623) ~[dubbo-2.7.8.jar:2.7.8]
	at org.apache.dubbo.config.bootstrap.DubboBootstrap.initialize(DubboBootstrap.java:521) ~[dubbo-2.7.8.jar:2.7.8]
	at org.apache.dubbo.config.bootstrap.DubboBootstrap.start(DubboBootstrap.java:896) ~[dubbo-2.7.8.jar:2.7.8]
	at org.apache.dubbo.config.spring.context.DubboBootstrapApplicationListener.onContextRefreshedEvent(DubboBootstrapApplicationListener.java:59) ~[dubbo-2.7.8.jar:2.7.8]
	at org.apache.dubbo.config.spring.context.DubboBootstrapApplicationListener.onApplicationContextEvent(DubboBootstrapApplicationListener.java:52) ~[dubbo-2.7.8.jar:2.7.8]
	at org.apache.dubbo.config.spring.context.OneTimeExecutionApplicationContextEventListener.onApplicationEvent(OneTimeExecutionApplicationContextEventListener.java:40) ~[dubbo-2.7.8.jar:2.7.8]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:402) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:359) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:896) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:552) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:742) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:389) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:311) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1213) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1202) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
	at com.sf.dubbo.bootstrap.providerApplication.main(providerApplication.java:28) ~[classes/:na]

查看源码和调式发现:

String namespace = url.getParameter(CONFIG_NAMESPACE_KEY, DEFAULT_GROUP);
String apolloNamespace = StringUtils.isEmpty(namespace) ? url.getParameter(GROUP_KEY, DEFAULT_GROUP) : namespace;
dubboConfig = ConfigService.getConfig(apolloNamespace);
dubboConfigFile = ConfigService.getConfigFile(apolloNamespace, ConfigFileFormat.Properties);

这里截取的ParameterKey 不对,这里获取的是config.namespace,而在url内部的Parameter实际为namesapce,导致获取为空,由于给了默认值下面的语句判空也没有发挥任何作用,appConfigFile的值也未能正确获取到。

image

image

@furaul
Copy link

furaul commented Sep 10, 2020

在2.7.x较早的版本中,ConfigCenterConfig中的namespace等属性,都有一个@parameter注解,在ConfigCenterConfig实例转换成URL的时候,构建Url实体的parameter时,key使用的是@parameter里面的key属性。读取逻辑见org.apache.dubbo.common.constants.CommonConstants.CONFIG_NAMESPACE_KEY;

在2.7.x近期的版本中,ConfigCenterConfig中的namespace等属性去掉了@parameter注解,构建Url的时候,key使用的是属性名本身。

但是在Apollo、etcd等配置中心的实现类,比如ApolloDynamicConfiguration中,读取namespace的key使用的还是org.apache.dubbo.common.constants.CommonConstants.CONFIG_NAMESPACE_KEY,导致读取失败。

详情修改见 #6717

@AlbumenJ
Copy link
Member

close #6606 via #6717

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants