From 6777c073a1305d6314273eeea841768e5e6fef28 Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Tue, 16 May 2023 23:26:46 +0800 Subject: [PATCH] Support disable 2.6.x url configurators (#12332) --- .../org/apache/dubbo/registry/Constants.java | 2 ++ .../integration/RegistryDirectory.java | 11 +++++++---- .../registry/integration/RegistryProtocol.java | 18 ++++++++++++------ 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/Constants.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/Constants.java index 1f80c179de2..d21534436c4 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/Constants.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/Constants.java @@ -109,6 +109,8 @@ public interface Constants { String MIGRATION_THRESHOLD_KEY = "migration.threshold"; + String ENABLE_26X_CONFIGURATION_LISTEN = "enable-26x-configuration-listen"; + String ENABLE_CONFIGURATION_LISTEN = "enable-configuration-listen"; /** diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java index 0fbdcc036ea..9cbedfbc47f 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java @@ -83,6 +83,7 @@ import static org.apache.dubbo.common.constants.RegistryConstants.ROUTERS_CATEGORY; import static org.apache.dubbo.common.constants.RegistryConstants.ROUTE_PROTOCOL; import static org.apache.dubbo.registry.Constants.CONFIGURATORS_SUFFIX; +import static org.apache.dubbo.registry.Constants.ENABLE_26X_CONFIGURATION_LISTEN; import static org.apache.dubbo.rpc.Constants.MOCK_KEY; import static org.apache.dubbo.rpc.cluster.Constants.ROUTER_KEY; import static org.apache.dubbo.rpc.model.ScopeModelUtil.getModuleModel; @@ -170,11 +171,13 @@ public synchronized void notify(List urls) { .filter(this::isNotCompatibleFor26x) .collect(Collectors.groupingBy(this::judgeCategory)); - List configuratorURLs = categoryUrls.getOrDefault(CONFIGURATORS_CATEGORY, Collections.emptyList()); - this.configurators = Configurator.toConfigurators(configuratorURLs).orElse(this.configurators); + if (moduleModel.getModelEnvironment().getConfiguration().convert(Boolean.class, ENABLE_26X_CONFIGURATION_LISTEN, true)) { + List configuratorURLs = categoryUrls.getOrDefault(CONFIGURATORS_CATEGORY, Collections.emptyList()); + this.configurators = Configurator.toConfigurators(configuratorURLs).orElse(this.configurators); - List routerURLs = categoryUrls.getOrDefault(ROUTERS_CATEGORY, Collections.emptyList()); - toRouters(routerURLs).ifPresent(this::addRouters); + List routerURLs = categoryUrls.getOrDefault(ROUTERS_CATEGORY, Collections.emptyList()); + toRouters(routerURLs).ifPresent(this::addRouters); + } // providers List providerURLs = categoryUrls.getOrDefault(PROVIDERS_CATEGORY, Collections.emptyList()); diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java index 0d36bb0a180..c0b3dc116da 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java @@ -117,6 +117,7 @@ import static org.apache.dubbo.common.utils.UrlUtils.classifyUrls; import static org.apache.dubbo.registry.Constants.CONFIGURATORS_SUFFIX; import static org.apache.dubbo.registry.Constants.DEFAULT_REGISTRY_RETRY_PERIOD; +import static org.apache.dubbo.registry.Constants.ENABLE_26X_CONFIGURATION_LISTEN; import static org.apache.dubbo.registry.Constants.ENABLE_CONFIGURATION_LISTEN; import static org.apache.dubbo.registry.Constants.PROVIDER_PROTOCOL; import static org.apache.dubbo.registry.Constants.REGISTER_IP_KEY; @@ -272,9 +273,12 @@ public Exporter export(final Invoker originInvoker) throws RpcExceptio exporter.setSubscribeUrl(overrideSubscribeUrl); exporter.setNotifyListener(overrideSubscribeListener); - if (!registry.isServiceDiscovery()) { - // Deprecated! Subscribe to override rules in 2.6.x or before. - registry.subscribe(overrideSubscribeUrl, overrideSubscribeListener); + ApplicationModel applicationModel = getApplicationModel(providerUrl.getScopeModel()); + if (applicationModel.getModelEnvironment().getConfiguration().convert(Boolean.class, ENABLE_26X_CONFIGURATION_LISTEN, true)) { + if (!registry.isServiceDiscovery()) { + // Deprecated! Subscribe to override rules in 2.6.x or before. + registry.subscribe(overrideSubscribeUrl, overrideSubscribeListener); + } } notifyExport(exporter); @@ -954,10 +958,12 @@ public synchronized void unregister() { Set listeners = overrideListeners.get(subscribeUrl); if (listeners != null) { if (listeners.remove(notifyListener)) { - if (!registry.isServiceDiscovery()) { - registry.unsubscribe(subscribeUrl, notifyListener); - } ApplicationModel applicationModel = getApplicationModel(registerUrl.getScopeModel()); + if (applicationModel.getModelEnvironment().getConfiguration().convert(Boolean.class, ENABLE_26X_CONFIGURATION_LISTEN, true)) { + if (!registry.isServiceDiscovery()) { + registry.unsubscribe(subscribeUrl, notifyListener); + } + } if (applicationModel.getModelEnvironment().getConfiguration().convert(Boolean.class, ENABLE_CONFIGURATION_LISTEN, true)) { for (ModuleModel moduleModel : applicationModel.getPubModuleModels()) { if (moduleModel.getServiceRepository().getExportedServices().size() > 0) {