You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2020/09/15 10:50:40 UTC

[dubbo] branch 3.0 updated: add logger to critical path (#6744)

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

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


The following commit(s) were added to refs/heads/3.0 by this push:
     new 4204be7  add logger to critical path (#6744)
4204be7 is described below

commit 4204be7b28484944907d73f23f191d89964dcdbb
Author: ken.lj <ke...@gmail.com>
AuthorDate: Tue Sep 15 18:50:22 2020 +0800

    add logger to critical path (#6744)
---
 .../dubbo/config/bootstrap/DubboBootstrap.java     |  7 +++
 .../registry/client/ServiceDiscoveryRegistry.java  |  7 ++-
 .../listener/ServiceInstancesChangedListener.java  |  9 ++++
 .../metadata/store/RemoteMetadataServiceImpl.java  |  4 ++
 .../DefaultMigrationAddressComparator.java         |  4 ++
 .../client/migration/MigrationInvoker.java         | 63 +++++++++++++++++-----
 .../client/migration/MigrationRuleListener.java    |  7 ++-
 .../ServiceDiscoveryMigrationInvoker.java          |  4 +-
 .../InterfaceCompatibleRegistryProtocol.java       |  4 +-
 .../registry/integration/RegistryProtocol.java     | 19 +++----
 .../integration/RegistryProtocolListener.java      |  3 +-
 11 files changed, 102 insertions(+), 29 deletions(-)

diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/DubboBootstrap.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/DubboBootstrap.java
index 34977b3..9aa3455 100644
--- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/DubboBootstrap.java
+++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/DubboBootstrap.java
@@ -1173,11 +1173,18 @@ public class DubboBootstrap extends GenericEventListener {
 
     private void doRegisterServiceInstance(ServiceInstance serviceInstance) {
         //FIXME
+        if (logger.isInfoEnabled()) {
+            logger.info("Start publishing metadata to remote center, this only makes sense for applications enabled remote metadata center.");
+        }
         publishMetadataToRemote(serviceInstance);
 
+        logger.info("Start registering instance address to registry.");
         getServiceDiscoveries().forEach(serviceDiscovery ->
         {
             calInstanceRevision(serviceDiscovery, serviceInstance);
+            if (logger.isDebugEnabled()) {
+                logger.info("Start registering instance address to registry" + serviceDiscovery.getUrl() + ", instance " + serviceInstance);
+            }
             // register metadata
             serviceDiscovery.register(serviceInstance);
         });
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java
index 35f18ce..f3cc973 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java
@@ -260,6 +260,7 @@ public class ServiceDiscoveryRegistry implements Registry {
         writableMetadataService.subscribeURL(url);
 
         Set<String> serviceNames = getServices(url, listener);
+
         if (CollectionUtils.isEmpty(serviceNames)) {
             throw new IllegalStateException("Should has at least one way to know which services this interface belongs to, subscription url: " + url);
         }
@@ -363,12 +364,16 @@ public class ServiceDiscoveryRegistry implements Registry {
 
         String serviceNames = subscribedURL.getParameter(PROVIDED_BY);
         if (StringUtils.isNotEmpty(serviceNames)) {
+            logger.info(subscribedURL.getServiceInterface() + " mapping to " + serviceNames + " instructed by provided-by set by user.");
             subscribedServices.addAll(parseServices(serviceNames));
         }
 
         if (isEmpty(subscribedServices)) {
-            subscribedServices.addAll(findMappedServices(subscribedURL, new DefaultMappingListener(subscribedURL, subscribedServices, listener)));
+            Set<String> mappedServices = findMappedServices(subscribedURL, new DefaultMappingListener(subscribedURL, subscribedServices, listener));
+            logger.info(subscribedURL.getServiceInterface() + " mapping to " + serviceNames + " instructed by remote metadata center.");
+            subscribedServices.addAll(mappedServices);
             if (isEmpty(subscribedServices)) {
+                logger.info(subscribedURL.getServiceInterface() + " mapping to " + serviceNames + " by default.");
                 subscribedServices.addAll(getSubscribedServices());
             }
         }
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/event/listener/ServiceInstancesChangedListener.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/event/listener/ServiceInstancesChangedListener.java
index c412547..87e0977 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/event/listener/ServiceInstancesChangedListener.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/event/listener/ServiceInstancesChangedListener.java
@@ -88,6 +88,9 @@ public class ServiceInstancesChangedListener implements ConditionalEventListener
         logger.info("Received instance notification, serviceName: " + event.getServiceName() + ", instances: " + event.getServiceInstances().size());
         String appName = event.getServiceName();
         allInstances.put(appName, event.getServiceInstances());
+        if (logger.isDebugEnabled()) {
+            logger.debug(event.getServiceInstances().toString());
+        }
 
         Map<String, List<ServiceInstance>> revisionToInstances = new HashMap<>();
         Map<String, Set<String>> localServiceToRevisions = new HashMap<>();
@@ -161,6 +164,9 @@ public class ServiceInstancesChangedListener implements ConditionalEventListener
         instance.getExtendParams().putIfAbsent(REGISTRY_CLUSTER_KEY, RegistryClusterIdentifier.getExtension(url).consumerKey(url));
         MetadataInfo metadataInfo;
         try {
+            if (logger.isDebugEnabled()) {
+                logger.info("Instance " + instance.getAddress() + " is using metadata type " + metadataType);
+            }
             if (REMOTE_METADATA_STORAGE_TYPE.equals(metadataType)) {
                 RemoteMetadataServiceImpl remoteMetadataService = MetadataUtils.getRemoteMetadataService();
                 metadataInfo = remoteMetadataService.getMetadata(instance);
@@ -168,6 +174,9 @@ public class ServiceInstancesChangedListener implements ConditionalEventListener
                 MetadataService metadataServiceProxy = MetadataUtils.getMetadataServiceProxy(instance, serviceDiscovery);
                 metadataInfo = metadataServiceProxy.getMetadataInfo(ServiceInstanceMetadataUtils.getExportedServicesRevision(instance));
             }
+            if (logger.isDebugEnabled()) {
+                logger.info("Metadata " + metadataInfo.toString());
+            }
         } catch (Exception e) {
             logger.error("Failed to load service metadata, metadta type is " + metadataType, e);
             metadataInfo = null;
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/store/RemoteMetadataServiceImpl.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/store/RemoteMetadataServiceImpl.java
index 01c4eff..209a9fa 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/store/RemoteMetadataServiceImpl.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/store/RemoteMetadataServiceImpl.java
@@ -69,6 +69,10 @@ public class RemoteMetadataServiceImpl {
                 if (metadataReport == null) {
                     metadataReport = getMetadataReports().entrySet().iterator().next().getValue();
                 }
+                logger.info("Publishing metadata to " + metadataReport.getClass().getSimpleName());
+                if (logger.isDebugEnabled()) {
+                    logger.debug(metadataInfo.toString());
+                }
                 metadataReport.publishAppMetadata(identifier, metadataInfo);
                 metadataInfo.markReported();
             }
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/DefaultMigrationAddressComparator.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/DefaultMigrationAddressComparator.java
index b13ac27..81c93d3 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/DefaultMigrationAddressComparator.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/DefaultMigrationAddressComparator.java
@@ -34,9 +34,11 @@ public class DefaultMigrationAddressComparator implements MigrationAddressCompar
     @Override
     public <T> boolean shouldMigrate(ClusterInvoker<T> serviceDiscoveryInvoker, ClusterInvoker<T> invoker) {
         if (!serviceDiscoveryInvoker.isAvailable()) {
+            logger.info("No instance address available, will not migrate.");
             return false;
         }
         if (!invoker.isAvailable()) {
+            logger.info("No interface address available, will migrate.");
             return true;
         }
 
@@ -55,6 +57,8 @@ public class DefaultMigrationAddressComparator implements MigrationAddressCompar
             threshold = DEFAULT_THREAD;
         }
 
+        logger.info("Instance address size " + newAddressSize + ", interface address size " + oldAddressSize + ", threshold " + threshold);
+
         if (newAddressSize != 0 && oldAddressSize == 0) {
             return true;
         }
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationInvoker.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationInvoker.java
index e82d164..c95dc88 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationInvoker.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationInvoker.java
@@ -18,6 +18,8 @@ package org.apache.dubbo.registry.client.migration;
 
 import org.apache.dubbo.common.URL;
 import org.apache.dubbo.common.extension.ExtensionLoader;
+import org.apache.dubbo.common.logger.Logger;
+import org.apache.dubbo.common.logger.LoggerFactory;
 import org.apache.dubbo.common.utils.StringUtils;
 import org.apache.dubbo.registry.Registry;
 import org.apache.dubbo.registry.client.migration.model.MigrationStep;
@@ -35,8 +37,10 @@ import java.util.Set;
 import static org.apache.dubbo.rpc.cluster.Constants.REFER_KEY;
 
 public class MigrationInvoker<T> implements MigrationClusterInvoker<T> {
+    private Logger logger = LoggerFactory.getLogger(MigrationInvoker.class);
 
     private URL url;
+    private URL consumerUrl;
     private Cluster cluster;
     private Registry registry;
     private Class<T> type;
@@ -50,8 +54,9 @@ public class MigrationInvoker<T> implements MigrationClusterInvoker<T> {
                             Cluster cluster,
                             Registry registry,
                             Class<T> type,
-                            URL url) {
-        this(null, null, registryProtocol, cluster, registry, type, url);
+                            URL url,
+                            URL consumerUrl) {
+        this(null, null, registryProtocol, cluster, registry, type, url, consumerUrl);
     }
 
     public MigrationInvoker(ClusterInvoker<T> invoker,
@@ -60,7 +65,8 @@ public class MigrationInvoker<T> implements MigrationClusterInvoker<T> {
                             Cluster cluster,
                             Registry registry,
                             Class<T> type,
-                            URL url) {
+                            URL url,
+                            URL consumerUrl) {
         this.invoker = invoker;
         this.serviceDiscoveryInvoker = serviceDiscoveryInvoker;
         this.registryProtocol = registryProtocol;
@@ -68,6 +74,7 @@ public class MigrationInvoker<T> implements MigrationClusterInvoker<T> {
         this.registry = registry;
         this.type = type;
         this.url = url;
+        this.consumerUrl = consumerUrl;
     }
 
     public ClusterInvoker<T> getInvoker() {
@@ -142,10 +149,12 @@ public class MigrationInvoker<T> implements MigrationClusterInvoker<T> {
     @Override
     public Result invoke(Invocation invocation) throws RpcException {
         if (!checkInvokerAvailable(serviceDiscoveryInvoker)) {
+            logger.debug("Using interface addresses to handle invocation, interface " + type.getName() + ", total address size " + invoker.getDirectory().getAllInvokers().size());
             return invoker.invoke(invocation);
         }
 
         if (!checkInvokerAvailable(invoker)) {
+            logger.debug("Using instance addresses to handle invocation, interface " + type.getName() + ", total address size " + serviceDiscoveryInvoker.getDirectory().getAllInvokers().size());
             return serviceDiscoveryInvoker.invoke(invocation);
         }
 
@@ -153,14 +162,6 @@ public class MigrationInvoker<T> implements MigrationClusterInvoker<T> {
     }
 
     @Override
-    public URL getUrl() {
-        if (invoker != null) {
-            return invoker.getUrl();
-        }
-        return serviceDiscoveryInvoker.getUrl();
-    }
-
-    @Override
     public boolean isAvailable() {
         return (invoker != null && invoker.isAvailable())
                 || (serviceDiscoveryInvoker != null && serviceDiscoveryInvoker.isAvailable());
@@ -177,19 +178,34 @@ public class MigrationInvoker<T> implements MigrationClusterInvoker<T> {
     }
 
     @Override
+    public URL getUrl() {
+        if (invoker != null) {
+            return invoker.getUrl();
+        } else if (serviceDiscoveryInvoker != null) {
+            return serviceDiscoveryInvoker.getUrl();
+        }
+
+        return consumerUrl;
+    }
+
+    @Override
     public URL getRegistryUrl() {
         if (invoker != null) {
             return invoker.getRegistryUrl();
+        } else if (serviceDiscoveryInvoker != null) {
+            serviceDiscoveryInvoker.getRegistryUrl();
         }
-        return serviceDiscoveryInvoker.getRegistryUrl();
+        return url;
     }
 
     @Override
     public Directory<T> getDirectory() {
         if (invoker != null) {
             return invoker.getDirectory();
+        } else if (serviceDiscoveryInvoker != null) {
+            return serviceDiscoveryInvoker.getDirectory();
         }
-        return serviceDiscoveryInvoker.getDirectory();
+        return null;
     }
 
     @Override
@@ -217,6 +233,9 @@ public class MigrationInvoker<T> implements MigrationClusterInvoker<T> {
 
     private synchronized void compareAddresses() {
         this.invokersChanged = true;
+        if (logger.isDebugEnabled()) {
+            logger.info("" + invoker.getDirectory().getAllInvokers().size());
+        }
 
         Set<MigrationAddressComparator> detectors = ExtensionLoader.getExtensionLoader(MigrationAddressComparator.class).getSupportedExtensionInstances();
         if (detectors != null && detectors.stream().allMatch(migrationDetector -> migrationDetector.shouldMigrate(serviceDiscoveryInvoker, invoker))) {
@@ -229,6 +248,9 @@ public class MigrationInvoker<T> implements MigrationClusterInvoker<T> {
     protected synchronized void destroyServiceDiscoveryInvoker() {
         this.currentAvailableInvoker = invoker;
         if (serviceDiscoveryInvoker != null) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("Destroying instance address invokers, will not listen for address changes until re-subscribed, " + type.getName());
+            }
             serviceDiscoveryInvoker.destroy();
             serviceDiscoveryInvoker = null;
         }
@@ -237,12 +259,18 @@ public class MigrationInvoker<T> implements MigrationClusterInvoker<T> {
     protected synchronized void discardServiceDiscoveryInvokerAddress() {
         this.currentAvailableInvoker = invoker;
         if (serviceDiscoveryInvoker != null) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("Discarding instance addresses, total size " + serviceDiscoveryInvoker.getDirectory().getAllInvokers().size());
+            }
             serviceDiscoveryInvoker.getDirectory().discordAddresses();
         }
     }
 
     protected synchronized void refreshServiceDiscoveryInvoker() {
         if (needRefresh(serviceDiscoveryInvoker)) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("Re-subscribing instance addresses, current interface " + type.getName());
+            }
             serviceDiscoveryInvoker = registryProtocol.getServiceDiscoveryInvoker(cluster, registry, type, url);
         }
     }
@@ -250,6 +278,9 @@ public class MigrationInvoker<T> implements MigrationClusterInvoker<T> {
     protected synchronized void refreshInterfaceInvoker() {
         if (needRefresh(invoker)) {
             // FIXME invoker.destroy();
+            if (logger.isDebugEnabled()) {
+                logger.debug("Re-subscribing interface addresses for interface " + type.getName());
+            }
             invoker = registryProtocol.getInvoker(cluster, registry, type, url);
         }
     }
@@ -257,6 +288,9 @@ public class MigrationInvoker<T> implements MigrationClusterInvoker<T> {
     protected synchronized void destroyInterfaceInvoker() {
         this.currentAvailableInvoker = serviceDiscoveryInvoker;
         if (invoker != null) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("Destroying interface address invokers, will not listen for address changes until re-subscribed, " + type.getName());
+            }
             invoker.destroy();
             invoker = null;
         }
@@ -265,6 +299,9 @@ public class MigrationInvoker<T> implements MigrationClusterInvoker<T> {
     protected synchronized void discardInterfaceInvokerAddress() {
         this.currentAvailableInvoker = serviceDiscoveryInvoker;
         if (invoker != null) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("Discarding interface addresses, total address size " + invoker.getDirectory().getAllInvokers().size());
+            }
             invoker.getDirectory().discordAddresses();
         }
     }
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationRuleListener.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationRuleListener.java
index a300025..2c3a904 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationRuleListener.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationRuleListener.java
@@ -16,6 +16,7 @@
  */
 package org.apache.dubbo.registry.client.migration;
 
+import org.apache.dubbo.common.URL;
 import org.apache.dubbo.common.config.configcenter.ConfigChangedEvent;
 import org.apache.dubbo.common.config.configcenter.ConfigurationListener;
 import org.apache.dubbo.common.config.configcenter.DynamicConfiguration;
@@ -49,6 +50,7 @@ public class MigrationRuleListener implements RegistryProtocolListener, Configur
     public MigrationRuleListener() {
         this.configuration = ApplicationModel.getEnvironment().getDynamicConfiguration().orElseGet(null);
 
+        logger.info("Listening for migration rules on dataId-" + RULE_KEY + " group-" + DUBBO_SERVICEDISCOVERY_MIGRATION);
         configuration.addListener(RULE_KEY, DUBBO_SERVICEDISCOVERY_MIGRATION, this);
 
         String rawRule = configuration.getConfig(RULE_KEY, DUBBO_SERVICEDISCOVERY_MIGRATION);
@@ -66,6 +68,9 @@ public class MigrationRuleListener implements RegistryProtocolListener, Configur
             return;
         }
 
+        logger.info("Using the following migration rule to migrate:");
+        logger.info(rawRule);
+
         if (CollectionUtils.isNotEmpty(listeners)) {
             listeners.forEach(listener -> listener.doMigrate(rawRule));
         }
@@ -77,7 +82,7 @@ public class MigrationRuleListener implements RegistryProtocolListener, Configur
     }
 
     @Override
-    public synchronized void onRefer(RegistryProtocol registryProtocol, ClusterInvoker<?> invoker) {
+    public synchronized void onRefer(RegistryProtocol registryProtocol, ClusterInvoker<?> invoker, URL url) {
         MigrationInvoker<?> migrationInvoker = (MigrationInvoker<?>) invoker;
 
         MigrationRuleHandler<?> migrationListener = new MigrationRuleHandler<>(migrationInvoker);
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/ServiceDiscoveryMigrationInvoker.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/ServiceDiscoveryMigrationInvoker.java
index e9aebe3..ab08c86 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/ServiceDiscoveryMigrationInvoker.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/ServiceDiscoveryMigrationInvoker.java
@@ -27,8 +27,8 @@ import org.apache.dubbo.rpc.cluster.ClusterInvoker;
 
 public class ServiceDiscoveryMigrationInvoker<T> extends MigrationInvoker<T> {
 
-    public ServiceDiscoveryMigrationInvoker(RegistryProtocol registryProtocol, Cluster cluster, Registry registry, Class<T> type, URL url) {
-        super(registryProtocol, cluster, registry, type, url);
+    public ServiceDiscoveryMigrationInvoker(RegistryProtocol registryProtocol, Cluster cluster, Registry registry, Class<T> type, URL url, URL consumerUrl) {
+        super(registryProtocol, cluster, registry, type, url, consumerUrl);
     }
 
     @Override
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/InterfaceCompatibleRegistryProtocol.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/InterfaceCompatibleRegistryProtocol.java
index d073aff..b7374a3 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/InterfaceCompatibleRegistryProtocol.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/InterfaceCompatibleRegistryProtocol.java
@@ -65,9 +65,9 @@ public class InterfaceCompatibleRegistryProtocol extends RegistryProtocol {
         return doCreateInvoker(directory, cluster, registry, type);
     }
 
-    protected <T> ClusterInvoker<T> getMigrationInvoker(RegistryProtocol registryProtocol, Cluster cluster, Registry registry, Class<T> type, URL url) {
+    protected <T> ClusterInvoker<T> getMigrationInvoker(RegistryProtocol registryProtocol, Cluster cluster, Registry registry, Class<T> type, URL url, URL consumerUrl) {
 //        ClusterInvoker<T> invoker = getInvoker(cluster, registry, type, url);
-        return new MigrationInvoker<T>(registryProtocol, cluster, registry, type, url);
+        return new MigrationInvoker<T>(registryProtocol, cluster, registry, type, url, consumerUrl);
     }
 
 }
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java
index cf4a708..babcce2 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java
@@ -443,31 +443,32 @@ public class RegistryProtocol implements Protocol {
         String group = qs.get(GROUP_KEY);
         if (group != null && group.length() > 0) {
             if ((COMMA_SPLIT_PATTERN.split(group)).length > 1 || "*".equals(group)) {
-                return doRefer(Cluster.getCluster(MergeableCluster.NAME), registry, type, url);
+                return doRefer(Cluster.getCluster(MergeableCluster.NAME), registry, type, url, qs);
             }
         }
 
         Cluster cluster = Cluster.getCluster(qs.get(CLUSTER_KEY));
-        return doRefer(cluster, registry, type, url);
+        return doRefer(cluster, registry, type, url, qs);
     }
 
-    protected <T> Invoker<T> doRefer(Cluster cluster, Registry registry, Class<T> type, URL url) {
-        ClusterInvoker<T> migrationInvoker = getMigrationInvoker(this, cluster, registry, type, url);
-        return interceptInvoker(migrationInvoker, url);
+    protected <T> Invoker<T> doRefer(Cluster cluster, Registry registry, Class<T> type, URL url, Map<String, String> parameters) {
+        URL consumerUrl = new URL(CONSUMER_PROTOCOL, parameters.remove(REGISTER_IP_KEY), 0, type.getName(), parameters);
+        ClusterInvoker<T> migrationInvoker = getMigrationInvoker(this, cluster, registry, type, url, consumerUrl);
+        return interceptInvoker(migrationInvoker, url, consumerUrl);
     }
 
-    protected <T> ClusterInvoker<T> getMigrationInvoker(RegistryProtocol registryProtocol, Cluster cluster, Registry registry, Class<T> type, URL url) {
-        return new ServiceDiscoveryMigrationInvoker<T>(registryProtocol, cluster, registry, type, url);
+    protected <T> ClusterInvoker<T> getMigrationInvoker(RegistryProtocol registryProtocol, Cluster cluster, Registry registry, Class<T> type, URL url, URL consumerUrl) {
+        return new ServiceDiscoveryMigrationInvoker<T>(registryProtocol, cluster, registry, type, url, consumerUrl);
     }
 
-    protected <T> Invoker<T> interceptInvoker(ClusterInvoker<T> invoker, URL url) {
+    protected <T> Invoker<T> interceptInvoker(ClusterInvoker<T> invoker, URL url, URL consumerUrl) {
         List<RegistryProtocolListener> listeners = findRegistryProtocolListeners(url);
         if (CollectionUtils.isEmpty(listeners)) {
             return invoker;
         }
 
         for (RegistryProtocolListener listener : listeners) {
-            listener.onRefer(this, invoker);
+            listener.onRefer(this, invoker, consumerUrl);
         }
         return invoker;
     }
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocolListener.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocolListener.java
index 41926b8..c4cade5 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocolListener.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocolListener.java
@@ -41,9 +41,10 @@ public interface RegistryProtocolListener {
      *
      * @param registryProtocol RegistryProtocol instance
      * @param invoker          invoker
+     * @param url
      * @see RegistryProtocol#refer(Class, URL)
      */
-    void onRefer(RegistryProtocol registryProtocol, ClusterInvoker<?> invoker);
+    void onRefer(RegistryProtocol registryProtocol, ClusterInvoker<?> invoker, URL url);
 
     /**
      * Notify RegistryProtocol's listeners when the protocol is destroyed