You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by me...@apache.org on 2020/04/28 09:03:59 UTC
[dubbo] branch master updated: [Dubbo-5978] fix nacos-registry
dubbo.registry.group no effect (#5997)
This is an automated email from the ASF dual-hosted git repository.
mercyblitz 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 acd6e87 [Dubbo-5978] fix nacos-registry dubbo.registry.group no effect (#5997)
acd6e87 is described below
commit acd6e87ddeba5ea2a491b04799cd55e2dce2541f
Author: Huangxuny1 <gh...@gmail.com>
AuthorDate: Tue Apr 28 17:03:19 2020 +0800
[Dubbo-5978] fix nacos-registry dubbo.registry.group no effect (#5997)
* register and subscriber with group name
* polish
---
.../apache/dubbo/registry/nacos/NacosRegistry.java | 50 ++++++++++++++++------
1 file changed, 37 insertions(+), 13 deletions(-)
diff --git a/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java
index a13fa88..187da71 100644
--- a/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java
+++ b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java
@@ -17,6 +17,7 @@
package org.apache.dubbo.registry.nacos;
+import com.alibaba.nacos.api.common.Constants;
import com.google.common.collect.Lists;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.URLBuilder;
@@ -138,7 +139,8 @@ public class NacosRegistry extends FailbackRegistry {
execute(namingService -> {
Set<String> serviceNames = getServiceNames(url, null);
for (String serviceName : serviceNames) {
- List<Instance> instances = namingService.getAllInstances(serviceName);
+ List<Instance> instances = namingService.getAllInstances(serviceName,
+ getUrl().getParameter(GROUP_KEY, Constants.DEFAULT_GROUP));
urls.addAll(buildURLs(url, instances));
}
});
@@ -149,7 +151,14 @@ public class NacosRegistry extends FailbackRegistry {
public void doRegister(URL url) {
final String serviceName = getServiceName(url);
final Instance instance = createInstance(url);
- execute(namingService -> namingService.registerInstance(serviceName, instance));
+ /**
+ * namingService.registerInstance with {@link org.apache.dubbo.registry.support.AbstractRegistry#registryUrl}
+ * default {@link DEFAULT_GROUP}
+ *
+ * in https://github.com/apache/dubbo/issues/5978
+ */
+ execute(namingService -> namingService.registerInstance(serviceName,
+ getUrl().getParameter(GROUP_KEY, Constants.DEFAULT_GROUP), instance));
}
@Override
@@ -157,7 +166,10 @@ public class NacosRegistry extends FailbackRegistry {
execute(namingService -> {
String serviceName = getServiceName(url);
Instance instance = createInstance(url);
- namingService.deregisterInstance(serviceName, instance.getIp(), instance.getPort());
+ namingService.deregisterInstance(serviceName,
+ getUrl().getParameter(GROUP_KEY, Constants.DEFAULT_GROUP),
+ instance.getIp()
+ , instance.getPort());
});
}
@@ -166,8 +178,8 @@ public class NacosRegistry extends FailbackRegistry {
Set<String> serviceNames = getServiceNames(url, listener);
//Set corresponding serviceNames for easy search later
- if(isServiceNamesWithCompatibleMode(url)){
- for(String serviceName:serviceNames){
+ if (isServiceNamesWithCompatibleMode(url)) {
+ for (String serviceName : serviceNames) {
NacosInstanceManageUtil.setCorrespondingServiceNames(serviceName, serviceNames);
}
}
@@ -183,9 +195,15 @@ public class NacosRegistry extends FailbackRegistry {
/**
* Get all instances with serviceNames to avoid instance overwrite and but with empty instance mentioned
* in https://github.com/apache/dubbo/issues/5885 and https://github.com/apache/dubbo/issues/5899
+ *
+ * namingService.getAllInstances with {@link org.apache.dubbo.registry.support.AbstractRegistry#registryUrl}
+ * default {@link DEFAULT_GROUP}
+ *
+ * in https://github.com/apache/dubbo/issues/5978
*/
for (String serviceName : serviceNames) {
- List<Instance> instances = namingService.getAllInstances(serviceName);
+ List<Instance> instances = namingService.getAllInstances(serviceName,
+ getUrl().getParameter(GROUP_KEY, Constants.DEFAULT_GROUP));
NacosInstanceManageUtil.initOrRefreshServiceInstanceList(serviceName, instances);
allCorrespondingInstanceList.addAll(instances);
}
@@ -194,9 +212,10 @@ public class NacosRegistry extends FailbackRegistry {
subscribeEventListener(serviceName, url, listener);
}
} else {
- List<Instance> instances = new LinkedList();
+ List<Instance> instances = new LinkedList<>();
for (String serviceName : serviceNames) {
- instances.addAll(namingService.getAllInstances(serviceName));
+ instances.addAll(namingService.getAllInstances(serviceName
+ , getUrl().getParameter(GROUP_KEY, Constants.DEFAULT_GROUP)));
notifySubscriber(url, listener, instances);
subscribeEventListener(serviceName, url, listener);
}
@@ -275,7 +294,8 @@ public class NacosRegistry extends FailbackRegistry {
execute(namingService -> {
- serviceNames.addAll(namingService.getServicesOfServer(1, Integer.MAX_VALUE).getData()
+ serviceNames.addAll(namingService.getServicesOfServer(1, Integer.MAX_VALUE,
+ getUrl().getParameter(GROUP_KEY, Constants.DEFAULT_GROUP)).getData()
.stream()
.map(NacosServiceName::new)
.filter(serviceName::isCompatible)
@@ -354,7 +374,8 @@ public class NacosRegistry extends FailbackRegistry {
execute(namingService -> {
int pageIndex = 1;
- ListView<String> listView = namingService.getServicesOfServer(pageIndex, PAGINATION_SIZE);
+ ListView<String> listView = namingService.getServicesOfServer(pageIndex, PAGINATION_SIZE,
+ getUrl().getParameter(GROUP_KEY, Constants.DEFAULT_GROUP));
// First page data
List<String> firstPageData = listView.getData();
// Append first page into list
@@ -370,7 +391,8 @@ public class NacosRegistry extends FailbackRegistry {
}
// If more than 1 page
while (pageIndex < pageNumbers) {
- listView = namingService.getServicesOfServer(++pageIndex, PAGINATION_SIZE);
+ listView = namingService.getServicesOfServer(++pageIndex, PAGINATION_SIZE,
+ getUrl().getParameter(GROUP_KEY, Constants.DEFAULT_GROUP));
serviceNames.addAll(listView.getData());
}
@@ -473,7 +495,7 @@ public class NacosRegistry extends FailbackRegistry {
List<Instance> instances = e.getInstances();
- if(isServiceNamesWithCompatibleMode(url)){
+ if (isServiceNamesWithCompatibleMode(url)) {
/**
* Get all instances with corresponding serviceNames to avoid instance overwrite and but with empty instance mentioned
* in https://github.com/apache/dubbo/issues/5885 and https://github.com/apache/dubbo/issues/5899
@@ -485,7 +507,9 @@ public class NacosRegistry extends FailbackRegistry {
notifySubscriber(url, listener, instances);
}
};
- namingService.subscribe(serviceName, eventListener);
+ namingService.subscribe(serviceName,
+ getUrl().getParameter(GROUP_KEY, Constants.DEFAULT_GROUP),
+ eventListener);
}
/**