Skip to content

Commit

Permalink
[3.0] Fix unsubscribe url == null (#8017)
Browse files Browse the repository at this point in the history
fixes #8009
  • Loading branch information
kevinw66 committed Jun 11, 2021
1 parent f07640f commit bdb2d31
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
Expand Up @@ -231,15 +231,15 @@ public void destroy() {
registry.unregister(getRegisteredConsumerUrl());
}
} catch (Throwable t) {
logger.warn("unexpected error when unregister service " + serviceKey + "from registry" + registry.getUrl(), t);
logger.warn("unexpected error when unregister service " + serviceKey + " from registry: " + registry.getUrl(), t);
}
// unsubscribe.
try {
if (getConsumerUrl() != null && registry != null && registry.isAvailable()) {
if (getSubscribeUrl() != null && registry != null && registry.isAvailable()) {
registry.unsubscribe(getSubscribeUrl(), this);
}
} catch (Throwable t) {
logger.warn("unexpected error when unsubscribe service " + serviceKey + "from registry " + registry.getUrl(), t);
logger.warn("unexpected error when unsubscribe service " + serviceKey + " from registry: " + registry.getUrl(), t);
}

ExtensionLoader<AddressListener> addressListenerExtensionLoader = ExtensionLoader.getExtensionLoader(AddressListener.class);
Expand Down
Expand Up @@ -101,15 +101,15 @@ public RegistryDirectory(Class<T> serviceType, URL url) {

@Override
public void subscribe(URL url) {
setConsumerUrl(url);
setSubscribeUrl(url);
CONSUMER_CONFIGURATION_LISTENER.addNotifyListener(this);
referenceConfigurationListener = new ReferenceConfigurationListener(this, url);
registry.subscribe(url, this);
}

@Override
public void unSubscribe(URL url) {
setConsumerUrl(null);
setSubscribeUrl(null);
CONSUMER_CONFIGURATION_LISTENER.removeNotifyListener(this);
referenceConfigurationListener.stop();
registry.unsubscribe(url, this);
Expand Down
Expand Up @@ -503,8 +503,9 @@ protected <T> ClusterInvoker<T> doCreateInvoker(DynamicDirectory<T> directory, C
directory.setProtocol(protocol);
// all attributes of REFER_KEY
Map<String, String> parameters = new HashMap<String, String>(directory.getConsumerUrl().getParameters());
URL urlToRegistry = new ServiceConfigURL(parameters.get(PROTOCOL_KEY) == null ? DUBBO : parameters.get(PROTOCOL_KEY), parameters.remove(REGISTER_IP_KEY), 0, getPath(parameters, type), parameters);
URL consumerURL = directory.getConsumerUrl();
URL urlToRegistry = new ServiceConfigURL(
parameters.get(PROTOCOL_KEY) == null ? DUBBO : parameters.get(PROTOCOL_KEY),
parameters.remove(REGISTER_IP_KEY), 0, getPath(parameters, type), parameters);
if (directory.isShouldRegister()) {
directory.setRegisteredConsumerUrl(urlToRegistry);
registry.register(directory.getRegisteredConsumerUrl());
Expand Down

0 comments on commit bdb2d31

Please sign in to comment.