Service not register to registry if specify register=false (#12584)

This commit is contained in:
Albumen Kevin 2023-06-22 14:35:41 +08:00 committed by GitHub
parent d6776e4008
commit cf2a63580e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -512,7 +512,8 @@ public class ServiceConfig<T> extends ServiceConfigBase<T> {
providerModel.setDestroyRunner(getDestroyRunner());
repository.registerProvider(providerModel);
List<URL> registryURLs = ConfigValidationUtils.loadRegistries(this, true);
List<URL> registryURLs = !Boolean.FALSE.equals(isRegister()) ?
ConfigValidationUtils.loadRegistries(this, true) : Collections.emptyList();
MetricsEventBus.post(RegistryEvent.toRsEvent(module.getApplicationModel(), getUniqueServiceName(), protocols.size() * registryURLs.size()),
() -> {
@ -546,6 +547,9 @@ public class ServiceConfig<T> extends ServiceConfigBase<T> {
processServiceExecutor(url);
if (CollectionUtils.isEmpty(registryURLs)) {
registerType = RegisterTypeEnum.NEVER_REGISTER;
}
exportUrl(url, registryURLs, registerType);
}

View File

@ -124,6 +124,7 @@ import static org.apache.dubbo.config.Constants.LAYER_KEY;
import static org.apache.dubbo.config.Constants.NAME;
import static org.apache.dubbo.config.Constants.ORGANIZATION;
import static org.apache.dubbo.config.Constants.OWNER;
import static org.apache.dubbo.config.Constants.REGISTER_KEY;
import static org.apache.dubbo.config.Constants.STATUS_KEY;
import static org.apache.dubbo.monitor.Constants.LOGSTAT_PROTOCOL;
import static org.apache.dubbo.registry.Constants.REGISTER_IP_KEY;
@ -225,7 +226,10 @@ public class ConfigValidationUtils {
.setScopeModel(interfaceConfig.getScopeModel())
.build();
// provider delay register state will be checked in RegistryProtocol#export
if (provider || url.getParameter(SUBSCRIBE_KEY, true)) {
if (provider && url.getParameter(REGISTER_KEY, true)) {
registryList.add(url);
}
if (!provider && url.getParameter(SUBSCRIBE_KEY, true)) {
registryList.add(url);
}
}