This is an automated email from the ASF dual-hosted git repository.

albumenj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/master by this push:
     new 9633f6b  fix ServiceNameMapping didn't work problem. (#7723)
9633f6b is described below

commit 9633f6b9761ae7e2dedd682462ff9d01059417fc
Author: 赵延 <[email protected]>
AuthorDate: Thu May 13 11:39:50 2021 +0800

    fix ServiceNameMapping didn't work problem. (#7723)
---
 .../src/main/java/org/apache/dubbo/config/ServiceConfig.java  | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

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 5e8bed2..439f822 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
@@ -28,6 +28,7 @@ import org.apache.dubbo.common.utils.CollectionUtils;
 import org.apache.dubbo.common.utils.ConfigUtils;
 import org.apache.dubbo.common.utils.NamedThreadFactory;
 import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.common.utils.UrlUtils;
 import org.apache.dubbo.config.annotation.Service;
 import org.apache.dubbo.config.bootstrap.DubboBootstrap;
 import org.apache.dubbo.config.event.ServiceConfigExportedEvent;
@@ -82,7 +83,9 @@ import static 
org.apache.dubbo.common.constants.CommonConstants.REMOTE_METADATA_
 import static org.apache.dubbo.common.constants.CommonConstants.REVISION_KEY;
 import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY;
 import static org.apache.dubbo.common.constants.RegistryConstants.DYNAMIC_KEY;
+import static 
org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_TYPE_KEY;
 import static 
org.apache.dubbo.common.constants.RegistryConstants.SERVICE_REGISTRY_PROTOCOL;
+import static 
org.apache.dubbo.common.constants.RegistryConstants.SERVICE_REGISTRY_TYPE;
 import static org.apache.dubbo.common.utils.NetUtils.getAvailablePort;
 import static org.apache.dubbo.common.utils.NetUtils.getLocalHost;
 import static org.apache.dubbo.common.utils.NetUtils.isInvalidLocalHost;
@@ -216,7 +219,7 @@ public class ServiceConfig<T> extends ServiceConfigBase<T> {
         exportedURLs.forEach(url -> {
             // dubbo2.7.x does not register serviceNameMapping information 
with the registry by default.
             // Only when the user manually turns on the service introspection, 
can he register with the registration center.
-            boolean isServiceDiscovery = 
SERVICE_REGISTRY_PROTOCOL.equals(url.getProtocol());
+            boolean isServiceDiscovery = 
UrlUtils.isServiceDiscoveryRegistryType(url);
             if (isServiceDiscovery) {
                 Map<String, String> parameters = 
getApplication().getParameters();
                 ServiceNameMapping.getExtension(parameters != null ? 
parameters.get(MAPPING_KEY) : null).map(url);
@@ -482,6 +485,10 @@ public class ServiceConfig<T> extends ServiceConfigBase<T> 
{
             if (!SCOPE_LOCAL.equalsIgnoreCase(scope)) {
                 if (CollectionUtils.isNotEmpty(registryURLs)) {
                     for (URL registryURL : registryURLs) {
+                        if 
(SERVICE_REGISTRY_PROTOCOL.equals(registryURL.getProtocol())) {
+                            url = url.addParameterIfAbsent(REGISTRY_TYPE_KEY, 
SERVICE_REGISTRY_TYPE);
+                        }
+
                         //if protocol is only injvm ,not register
                         if 
(LOCAL_PROTOCOL.equalsIgnoreCase(url.getProtocol())) {
                             continue;
@@ -747,7 +754,7 @@ public class ServiceConfig<T> extends ServiceConfigBase<T> {
 
     public String getServiceName() {
 
-        if(!StringUtils.isBlank(serviceName)){
+        if (!StringUtils.isBlank(serviceName)) {
             return serviceName;
         }
         String generateVersion = version;

Reply via email to