Make Dubbo2.7.x not register serviceNameMapping information with the registry by default. (#7672)
diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java
index c278951..885da0d 100644
--- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java
+++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java
@@ -82,6 +82,7 @@
import static org.apache.dubbo.common.constants.CommonConstants.REVISION_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.DYNAMIC_KEY;
+import static org.apache.dubbo.common.constants.RegistryConstants.SERVICE_REGISTRY_PROTOCOL;
import static org.apache.dubbo.common.utils.NetUtils.getAvailablePort;
import static org.apache.dubbo.common.utils.NetUtils.getLocalHost;
import static org.apache.dubbo.common.utils.NetUtils.isInvalidLocalHost;
@@ -114,7 +115,8 @@
/**
* A delayed exposure service timer
*/
- private static final ScheduledExecutorService DELAY_EXPORT_EXECUTOR = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("DubboServiceDelayExporter", true));
+ private static final ScheduledExecutorService DELAY_EXPORT_EXECUTOR =
+ Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("DubboServiceDelayExporter", true));
private static final Protocol PROTOCOL = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
@@ -210,8 +212,13 @@
public void exported() {
List<URL> exportedURLs = this.getExportedUrls();
exportedURLs.forEach(url -> {
- Map<String, String> parameters = getApplication().getParameters();
- ServiceNameMapping.getExtension(parameters != null ? parameters.get(MAPPING_KEY) : null).map(url);
+ // dubbo2.7.x does not register serviceNameMapping information with the registry by default.
+ // Only when the user manually turns on the service introspection, can he register with the registration center.
+ boolean isServiceDiscovery = SERVICE_REGISTRY_PROTOCOL.equals(url.getProtocol());
+ if (isServiceDiscovery) {
+ Map<String, String> parameters = getApplication().getParameters();
+ ServiceNameMapping.getExtension(parameters != null ? parameters.get(MAPPING_KEY) : null).map(url);
+ }
});
// dispatch a ServiceConfigExportedEvent since 2.7.4
dispatch(new ServiceConfigExportedEvent(this));
@@ -264,7 +271,8 @@
throw new IllegalStateException(e.getMessage(), e);
}
if (!interfaceClass.isAssignableFrom(localClass)) {
- throw new IllegalStateException("The local implementation class " + localClass.getName() + " not implement interface " + interfaceName);
+ throw new IllegalStateException(
+ "The local implementation class " + localClass.getName() + " not implement interface " + interfaceName);
}
}
if (stub != null) {
@@ -278,7 +286,8 @@
throw new IllegalStateException(e.getMessage(), e);
}
if (!interfaceClass.isAssignableFrom(stubClass)) {
- throw new IllegalStateException("The stub implementation class " + stubClass.getName() + " not implement interface " + interfaceName);
+ throw new IllegalStateException(
+ "The stub implementation class " + stubClass.getName() + " not implement interface " + interfaceName);
}
}
checkStubAndLocal(interfaceClass);
@@ -376,9 +385,12 @@
// one callback in the method
if (argument.getIndex() != -1) {
if (argtypes[argument.getIndex()].getName().equals(argument.getType())) {
- AbstractConfig.appendParameters(map, argument, method.getName() + "." + argument.getIndex());
+ AbstractConfig
+ .appendParameters(map, argument, method.getName() + "." + argument.getIndex());
} else {
- throw new IllegalArgumentException("Argument config error : the index attribute and type attribute not match :index :" + argument.getIndex() + ", type:" + argument.getType());
+ throw new IllegalArgumentException(
+ "Argument config error : the index attribute and type attribute not match :index :" +
+ argument.getIndex() + ", type:" + argument.getType());
}
} else {
// multiple callbacks in the method
@@ -387,7 +399,9 @@
if (argclazz.getName().equals(argument.getType())) {
AbstractConfig.appendParameters(map, argument, method.getName() + "." + j);
if (argument.getIndex() != -1 && argument.getIndex() != j) {
- throw new IllegalArgumentException("Argument config error : the index attribute and type attribute not match :index :" + argument.getIndex() + ", type:" + argument.getType());
+ throw new IllegalArgumentException(
+ "Argument config error : the index attribute and type attribute not match :index :" +
+ argument.getIndex() + ", type:" + argument.getType());
}
}
}
@@ -398,7 +412,8 @@
} else if (argument.getIndex() != -1) {
AbstractConfig.appendParameters(map, argument, method.getName() + "." + argument.getIndex());
} else {
- throw new IllegalArgumentException("Argument config must set index or type attribute.eg: <dubbo:argument index='0' .../> or <dubbo:argument type=xxx .../>");
+ throw new IllegalArgumentException(
+ "Argument config must set index or type attribute.eg: <dubbo:argument index='0' .../> or <dubbo:argument type=xxx .../>");
}
}
@@ -476,7 +491,8 @@
}
if (logger.isInfoEnabled()) {
if (url.getParameter(REGISTER_KEY, true)) {
- logger.info("Register dubbo service " + interfaceClass.getName() + " url " + url + " to registry " + registryURL);
+ logger.info("Register dubbo service " + interfaceClass.getName() + " url " + url + " to registry " +
+ registryURL);
} else {
logger.info("Export dubbo service " + interfaceClass.getName() + " to url " + url);
}
@@ -488,7 +504,8 @@
registryURL = registryURL.addParameter(PROXY_KEY, proxy);
}
- Invoker<?> invoker = PROXY_FACTORY.getInvoker(ref, (Class) interfaceClass, registryURL.addParameterAndEncoded(EXPORT_KEY, url.toFullString()));
+ Invoker<?> invoker = PROXY_FACTORY.getInvoker(ref, (Class) interfaceClass,
+ registryURL.addParameterAndEncoded(EXPORT_KEY, url.toFullString()));
DelegateProviderMetaDataInvoker wrapperInvoker = new DelegateProviderMetaDataInvoker(invoker, this);
Exporter<?> exporter = PROTOCOL.export(wrapperInvoker);
@@ -601,7 +618,8 @@
// registry ip is not used for bind ip by default
String hostToRegistry = getValueFromConfig(protocolConfig, DUBBO_IP_TO_REGISTRY);
if (hostToRegistry != null && hostToRegistry.length() > 0 && isInvalidLocalHost(hostToRegistry)) {
- throw new IllegalArgumentException("Specified invalid registry ip from property:" + DUBBO_IP_TO_REGISTRY + ", value:" + hostToRegistry);
+ throw new IllegalArgumentException(
+ "Specified invalid registry ip from property:" + DUBBO_IP_TO_REGISTRY + ", value:" + hostToRegistry);
} else if (StringUtils.isEmpty(hostToRegistry)) {
// bind ip is used as registry ip by default
hostToRegistry = hostToBind;