Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apply #3295 to 2.6 branch #3502

Merged
merged 2 commits into from
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public class RegistryDirectory<T> extends AbstractDirectory<T> implements Notify

private volatile URL overrideDirectoryUrl; // Initialization at construction time, assertion not null, and always assign non null value

private volatile URL registeredConsumerUrl;

/**
* override rules
* Priority: override>-D>consumer>provider
Expand Down Expand Up @@ -164,6 +166,16 @@ public void destroy() {
if (isDestroyed()) {
return;
}

// unregister.
try {
if (getRegisteredConsumerUrl() != null && registry != null && registry.isAvailable()) {
registry.unregister(getRegisteredConsumerUrl());
}
} catch (Throwable t) {
logger.warn("unexpected error when unregister service " + serviceKey + "from registry" + registry.getUrl(), t);
}

// unsubscribe.
try {
if (getConsumerUrl() != null && registry != null && registry.isAvailable()) {
Expand Down Expand Up @@ -612,6 +624,14 @@ public URL getUrl() {
return this.overrideDirectoryUrl;
}

public URL getRegisteredConsumerUrl() {
return registeredConsumerUrl;
}

public void setRegisteredConsumerUrl(URL registeredConsumerUrl) {
this.registeredConsumerUrl = registeredConsumerUrl;
}

@Override
public boolean isAvailable() {
if (isDestroyed()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
import static com.alibaba.dubbo.common.Constants.QOS_ENABLE;
import static com.alibaba.dubbo.common.Constants.QOS_PORT;
import static com.alibaba.dubbo.common.Constants.VALIDATION_KEY;
import static com.alibaba.dubbo.common.Constants.CATEGORY_KEY;
import static com.alibaba.dubbo.common.Constants.CONSUMERS_CATEGORY;
import static com.alibaba.dubbo.common.Constants.CHECK_KEY;

/**
* RegistryProtocol
Expand Down Expand Up @@ -300,8 +303,9 @@ private <T> Invoker<T> doRefer(Cluster cluster, Registry registry, Class<T> type
URL subscribeUrl = new URL(Constants.CONSUMER_PROTOCOL, parameters.remove(Constants.REGISTER_IP_KEY), 0, type.getName(), parameters);
if (!Constants.ANY_VALUE.equals(url.getServiceInterface())
&& url.getParameter(Constants.REGISTER_KEY, true)) {
registry.register(subscribeUrl.addParameters(Constants.CATEGORY_KEY, Constants.CONSUMERS_CATEGORY,
Constants.CHECK_KEY, String.valueOf(false)));
URL registeredConsumerUrl = getRegisteredConsumerUrl(subscribeUrl, url);
registry.register(registeredConsumerUrl);
directory.setRegisteredConsumerUrl(registeredConsumerUrl);
}
directory.subscribe(subscribeUrl.addParameter(Constants.CATEGORY_KEY,
Constants.PROVIDERS_CATEGORY
Expand All @@ -313,6 +317,11 @@ private <T> Invoker<T> doRefer(Cluster cluster, Registry registry, Class<T> type
return invoker;
}

public URL getRegisteredConsumerUrl(final URL consumerUrl, URL registryUrl) {
return consumerUrl.addParameters(CATEGORY_KEY, CONSUMERS_CATEGORY,
CHECK_KEY, String.valueOf(false));
}

@Override
public void destroy() {
List<Exporter<?>> exporters = new ArrayList<Exporter<?>>(bounds.values());
Expand Down