Skip to content

Commit

Permalink
compatible service discovery, export noting suffix servicename, eg: {…
Browse files Browse the repository at this point in the history
…interface}:${version}
  • Loading branch information
呈铭 committed Apr 22, 2024
1 parent 5bed9cd commit 723ab69
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
8 changes: 4 additions & 4 deletions dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
Original file line number Diff line number Diff line change
Expand Up @@ -1300,11 +1300,11 @@ public String getColonSeparatedKey() {
*
* @return
*/
public String getColonSeparatedKey0() {
public String getCompatibleColonSeparatedKey() {
StringBuilder serviceNameBuilder = new StringBuilder();
serviceNameBuilder.append(this.getServiceInterface());
append0(serviceNameBuilder, VERSION_KEY);
append0(serviceNameBuilder, GROUP_KEY);
compatibleAppend(serviceNameBuilder, VERSION_KEY);
compatibleAppend(serviceNameBuilder, GROUP_KEY);
return serviceNameBuilder.toString();
}

Expand All @@ -1320,7 +1320,7 @@ private void append(StringBuilder target, String parameterName, boolean first) {
}
}

private void append0(StringBuilder target, String parameterName) {
private void compatibleAppend(StringBuilder target, String parameterName) {
String parameterValue = this.getParameter(parameterName);
if (!isBlank(parameterValue)) {
target.append(':');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,11 @@ public interface RegistryConstants {
String ENABLE_EMPTY_PROTECTION_KEY = "enable-empty-protection";
boolean DEFAULT_ENABLE_EMPTY_PROTECTION = false;
String REGISTER_CONSUMER_URL_KEY = "register-consumer-url";

/**
* export noting suffix servicename
* by default, dubbo export servicename is "${interface}:${version}:", this servicename with ':' suffix
* for compatible, we should export noting suffix servicename, eg: ${interface}:${version}
*/
String NACOE_REGISTER_COMPATIBLE = "nacos.register-compatible";
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import static org.apache.dubbo.common.constants.RegistryConstants.DEFAULT_ENABLE_EMPTY_PROTECTION;
import static org.apache.dubbo.common.constants.RegistryConstants.EMPTY_PROTOCOL;
import static org.apache.dubbo.common.constants.RegistryConstants.ENABLE_EMPTY_PROTECTION_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.NACOE_REGISTER_COMPATIBLE;
import static org.apache.dubbo.common.constants.RegistryConstants.PROVIDERS_CATEGORY;
import static org.apache.dubbo.common.constants.RegistryConstants.REGISTER_CONSUMER_URL_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.ROUTERS_CATEGORY;
Expand Down Expand Up @@ -123,14 +124,6 @@ public class NacosRegistry extends FailbackRegistry {
*/
private static final long LOOKUP_INTERVAL = Long.getLong("nacos.service.names.lookup.interval", 30);

/**
* export noting suffix servicename
* by default, dubbo export servicename is "${interface}:${version}:", this servicename with ':' suffix
* for compatible, we should export noting suffix servicename, eg: ${interface}:${version}
*/
private static final String DUUBO_NACOS_EXPORT_NOTING_SUFFIX_SERVICENAME =
System.getProperty("dubbo.nacos.export.noting.suffix.servicename", "false");

private static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(NacosRegistry.class);
private final NacosNamingServiceWrapper namingService;
/**
Expand Down Expand Up @@ -190,10 +183,10 @@ public void doRegister(URL url) {
serviceNames.add(serviceName);

// in https://github.com/apache/dubbo/issues/14075
if (Boolean.parseBoolean(DUUBO_NACOS_EXPORT_NOTING_SUFFIX_SERVICENAME)) {
if (getUrl().getParameter(NACOE_REGISTER_COMPATIBLE, false)) {
// servicename is "org.apache.dubbo.xxService:1.0.0"
String serviceName1 = getServiceName(url, true);
serviceNames.add(serviceName1);
String compatibleServiceName = getServiceName(url, true);
serviceNames.add(compatibleServiceName);
}

/**
Expand Down Expand Up @@ -229,7 +222,7 @@ public void doUnregister(final URL url) {
serviceNames.add(serviceName);

// in https://github.com/apache/dubbo/issues/14075
if (Boolean.parseBoolean(DUUBO_NACOS_EXPORT_NOTING_SUFFIX_SERVICENAME)) {
if (getUrl().getParameter(NACOE_REGISTER_COMPATIBLE, false)) {
// servicename is "org.apache.dubbo.xxService:1.0.0"
String serviceName1 = getServiceName(url, true);
serviceNames.add(serviceName1);
Expand Down Expand Up @@ -739,7 +732,7 @@ private NacosServiceName createServiceName(URL url) {

private String getServiceName(URL url, boolean needCompatible) {
if (needCompatible) {
return getServiceName0(url, url.getCategory(DEFAULT_CATEGORY));
return getCompatibleServiceName(url, url.getCategory(DEFAULT_CATEGORY));
}
return getServiceName(url, url.getCategory(DEFAULT_CATEGORY));
}
Expand All @@ -748,8 +741,8 @@ private String getServiceName(URL url, String category) {
return category + SERVICE_NAME_SEPARATOR + url.getColonSeparatedKey();
}

private String getServiceName0(URL url, String category) {
return category + SERVICE_NAME_SEPARATOR + url.getColonSeparatedKey0();
private String getCompatibleServiceName(URL url, String category) {
return category + SERVICE_NAME_SEPARATOR + url.getCompatibleColonSeparatedKey();
}

private void filterEnabledInstances(Collection<Instance> instances) {
Expand Down

0 comments on commit 723ab69

Please sign in to comment.