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 2018/11/21 02:25:41 UTC
[incubator-dubbo] 02/03: Fix reExport,
check url to registry changed before do register.
This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch dev-metadata
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git
commit ecc34c247cfea3724cea64fde9433b25ebcf0fe9
Author: ken.lj <ke...@gmail.com>
AuthorDate: Tue Nov 20 20:19:22 2018 +0800
Fix reExport, check url to registry changed before do register.
---
.../dubbo/registry/integration/RegistryProtocol.java | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
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 2c4781f..9ad920c 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
@@ -36,6 +36,7 @@ import org.apache.dubbo.registry.RegistryFactory;
import org.apache.dubbo.registry.RegistryService;
import org.apache.dubbo.registry.integration.parser.ConfigParser;
import org.apache.dubbo.registry.support.ProviderConsumerRegTable;
+import org.apache.dubbo.registry.support.ProviderInvokerWrapper;
import org.apache.dubbo.rpc.Exporter;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Protocol;
@@ -147,6 +148,11 @@ public class RegistryProtocol implements Protocol {
registry.register(registedProviderUrl);
}
+ public void unregister(URL registryUrl, URL registedProviderUrl) {
+ Registry registry = registryFactory.getRegistry(registryUrl);
+ registry.unregister(registedProviderUrl);
+ }
+
@Override
public <T> Exporter<T> export(final Invoker<T> originInvoker) throws RpcException {
URL registryUrl = getRegistryUrl(originInvoker);
@@ -226,9 +232,13 @@ public class RegistryProtocol implements Protocol {
final URL registeredProviderUrl = getRegistedProviderUrl(newInvokerUrl, registryUrl);
//decide if we need to re-publish
- boolean shouldReregister = ProviderConsumerRegTable.getProviderWrapper(originInvoker).isReg();
+ ProviderInvokerWrapper<T> providerInvokerWrapper = ProviderConsumerRegTable.getProviderWrapper(originInvoker);
ProviderConsumerRegTable.registerProvider(originInvoker, registryUrl, registeredProviderUrl);
- if (shouldReregister) {
+ /**
+ * Only if the new url going to Registry is different with the previous one should we do unregister and register.
+ */
+ if (providerInvokerWrapper.isReg() && !registeredProviderUrl.equals(providerInvokerWrapper.getProviderUrl())) {
+ unregister(registryUrl, providerInvokerWrapper.getProviderUrl());
register(registryUrl, registeredProviderUrl);
}