From fe71a91479896e8eb0087579ee19c954080ce8e5 Mon Sep 17 00:00:00 2001 From: "ken.lj" Date: Wed, 13 May 2020 13:49:43 +0800 Subject: [PATCH] put default version&group from provider and consumer into service metadata. (#6111) * put default version&group from provider and consumer into service metadata. --- README.md | 2 -- .../apache/dubbo/config/ReferenceConfigBase.java | 14 +++++++++++--- .../org/apache/dubbo/config/ServiceConfigBase.java | 14 +++++++++++--- .../org/apache/dubbo/config/ReferenceConfig.java | 6 +++--- .../org/apache/dubbo/config/ServiceConfig.java | 6 +++--- 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 0eebf9db8e4..c9e59ebe212 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,6 @@ Apache Dubbo is a high-performance, Java based open source RPC framework. Please We are now collecting dubbo user info in order to help us to improve Dubbo better, pls. kindly help us by providing yours on [issue#1012: Wanted: who's using dubbo](https://github.com/apache/dubbo/issues/1012), thanks :) -[使用文档](http://dubbo.apache.org/zh-cn/docs/user/new-features-in-a-glance.html)/[Documentation](http://dubbo.apache.org/en-us/docs/user/quick-start.html) - ## Architecture ![Architecture](http://dubbo.apache.org/img/architecture.png) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java b/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java index 4d633c093cf..a022813be7c 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java @@ -268,9 +268,17 @@ protected void computeValidRegistryIds() { @Parameter(excluded = true) public String getUniqueServiceName() { - String group = StringUtils.isEmpty(this.group) ? consumer.getGroup() : this.group; - String version = StringUtils.isEmpty(this.version) ? consumer.getVersion() : this.version; - return URL.buildKey(interfaceName, group, version); + return URL.buildKey(interfaceName, getGroup(), getVersion()); + } + + @Override + public String getVersion() { + return StringUtils.isEmpty(this.version) ? (consumer != null ? consumer.getVersion() : this.version) : this.version; + } + + @Override + public String getGroup() { + return StringUtils.isEmpty(this.group) ? (consumer != null ? consumer.getGroup() : this.group) : this.group; } public abstract T get(); diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java b/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java index 4a7c282eb91..650d74cac91 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java @@ -399,9 +399,17 @@ public String getPrefix() { @Parameter(excluded = true) public String getUniqueServiceName() { - String group = StringUtils.isEmpty(this.group) ? provider.getGroup() : this.group; - String version = StringUtils.isEmpty(this.version) ? provider.getVersion() : this.version; - return URL.buildKey(interfaceName, group, version); + return URL.buildKey(interfaceName, getGroup(), getVersion()); + } + + @Override + public String getGroup() { + return StringUtils.isEmpty(this.group) ? (provider != null ? provider.getGroup() : this.group) : this.group; + } + + @Override + public String getVersion() { + return StringUtils.isEmpty(this.version) ? (provider != null ? provider.getVersion() : this.version) : this.version; } private void computeValidProtocolIds() { diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java index 0523138ed3c..138a68e130c 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java @@ -399,9 +399,9 @@ public void checkAndUpdateSubConfigs() { } //init serivceMetadata - serviceMetadata.setVersion(version); - serviceMetadata.setGroup(group); - serviceMetadata.setDefaultGroup(group); + serviceMetadata.setVersion(getVersion()); + serviceMetadata.setGroup(getGroup()); + serviceMetadata.setDefaultGroup(getGroup()); serviceMetadata.setServiceType(getActualInterface()); serviceMetadata.setServiceInterfaceName(interfaceName); // TODO, uncomment this line once service key is unified diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java index 0792d12957d..3ad4545f382 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java @@ -193,9 +193,9 @@ public synchronized void export() { checkAndUpdateSubConfigs(); //init serviceMetadata - serviceMetadata.setVersion(version); - serviceMetadata.setGroup(group); - serviceMetadata.setDefaultGroup(group); + serviceMetadata.setVersion(getVersion()); + serviceMetadata.setGroup(getGroup()); + serviceMetadata.setDefaultGroup(getGroup()); serviceMetadata.setServiceType(getInterfaceClass()); serviceMetadata.setServiceInterfaceName(getInterface()); serviceMetadata.setTarget(getRef());