You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2018/12/03 11:35:30 UTC
[incubator-dubbo] 01/04: app level override rule should only
generate one url
This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch dev-metadata
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git
commit 7473662275afe8003a8208c1526bc662a2a8ac9d
Author: ken.lj <ke...@gmail.com>
AuthorDate: Mon Dec 3 19:15:11 2018 +0800
app level override rule should only generate one url
---
.../cluster/configurator}/parser/ConfigParser.java | 27 +++----
.../configurator}/parser/model/ConfigItem.java | 2 +-
.../parser/model/ConfiguratorConfig.java | 2 +-
.../configurator/parser}/ConfigParserTest.java | 31 ++++---
.../src/test/resources/AppAnyServices.yml | 0
.../src/test/resources/AppMultiServices.yml | 0
.../src/test/resources/AppNoService.yml | 0
.../test/resources/ConsumerSpecificProviders.yml | 0
.../src/test/resources/ServiceGroupVersion.yml | 0
.../src/test/resources/ServiceMultiApps.yml | 0
.../src/test/resources/ServiceNoApp.yml | 0
.../src/test/resources/ServiceNoRule.yml | 0
.../registry/integration/RegistryDirectory.java | 14 +++-
.../registry/integration/RegistryProtocol.java | 94 +++++++++-------------
14 files changed, 81 insertions(+), 89 deletions(-)
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/parser/ConfigParser.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/ConfigParser.java
similarity index 90%
rename from dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/parser/ConfigParser.java
rename to dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/ConfigParser.java
index a8464da..52384f3 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/parser/ConfigParser.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/ConfigParser.java
@@ -14,14 +14,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.dubbo.registry.integration.parser;
+package org.apache.dubbo.rpc.cluster.configurator.parser;
import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.StringUtils;
-import org.apache.dubbo.registry.integration.parser.model.ConfigItem;
-import org.apache.dubbo.registry.integration.parser.model.ConfiguratorConfig;
+import org.apache.dubbo.rpc.cluster.configurator.parser.model.ConfigItem;
+import org.apache.dubbo.rpc.cluster.configurator.parser.model.ConfiguratorConfig;
+
import org.yaml.snakeyaml.TypeDescription;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
@@ -36,7 +37,7 @@ import java.util.stream.Collectors;
*/
public class ConfigParser {
- public static List<URL> parseConfigurators(String rawConfig) {
+ public static List<URL> parseConfigurators(String rawConfig, String serviceKey) {
List<URL> urls = new ArrayList<>();
ConfiguratorConfig configuratorConfig = parseObject(rawConfig, ConfiguratorConfig.class);
@@ -45,7 +46,7 @@ public class ConfigParser {
if (ConfiguratorConfig.SCOPE_APPLICATION.equals(scope)) {
items.forEach(item -> urls.addAll(
- appItemToUrls(item, configuratorConfig.getKey())
+ appItemToUrls(item, configuratorConfig.getKey(), serviceKey)
.stream()
.map(u -> u.addParameter(Constants.CATEGORY_KEY, Constants.APP_DYNAMIC_CONFIGURATORS_CATEGORY))
.map(u -> u.addParameter(Constants.ENABLED_KEY, configuratorConfig.isEnabled()))
@@ -99,7 +100,7 @@ public class ConfigParser {
return urls;
}
- private static List<URL> appItemToUrls(ConfigItem item, String appKey) {
+ private static List<URL> appItemToUrls(ConfigItem item, String appKey, String serviceKey) {
List<URL> urls = new ArrayList<>();
List<String> addresses = item.getAddresses();
if (addresses == null) {
@@ -111,15 +112,13 @@ public class ConfigParser {
for (String addr : addresses) {
String urlStr = "override://" + addr + "/";
List<String> services = item.getServices();
- if (services == null) {
- services = new ArrayList<>();
- }
- if (services.size() == 0) {
- services.add("*");
- }
- for (String s : services) {
- urls.add(URL.valueOf(urlStr + appendService(s) + toParameterString(item) + "&application=" + appKey));
+ String targetService = serviceKey;
+ if (CollectionUtils.isEmpty(services) || services.contains("*")) {
+ targetService = "*";
+ } else if (!services.contains(serviceKey)) {
+ return urls;
}
+ urls.add(URL.valueOf(urlStr + appendService(targetService) + toParameterString(item) + "&application=" + appKey));
}
return urls;
}
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/parser/model/ConfigItem.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/ConfigItem.java
similarity index 97%
rename from dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/parser/model/ConfigItem.java
rename to dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/ConfigItem.java
index 70aaf36..a814ff3 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/parser/model/ConfigItem.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/ConfigItem.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.dubbo.registry.integration.parser.model;
+package org.apache.dubbo.rpc.cluster.configurator.parser.model;
import java.util.List;
import java.util.Map;
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/parser/model/ConfiguratorConfig.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/ConfiguratorConfig.java
similarity index 96%
rename from dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/parser/model/ConfiguratorConfig.java
rename to dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/ConfiguratorConfig.java
index f1d5034..dd0d3b0 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/parser/model/ConfiguratorConfig.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/ConfiguratorConfig.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.dubbo.registry.integration.parser.model;
+package org.apache.dubbo.rpc.cluster.configurator.parser.model;
import java.util.List;
diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/ConfigParserTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/configurator/parser/ConfigParserTest.java
similarity index 89%
rename from dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/ConfigParserTest.java
rename to dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/configurator/parser/ConfigParserTest.java
index 0b993fe..2c56ba0 100644
--- a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/ConfigParserTest.java
+++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/configurator/parser/ConfigParserTest.java
@@ -14,13 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.dubbo.registry;
+package org.apache.dubbo.rpc.cluster.configurator.parser;
import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
-import org.apache.dubbo.registry.integration.parser.ConfigParser;
-import org.apache.dubbo.registry.integration.parser.model.ConfigItem;
-import org.apache.dubbo.registry.integration.parser.model.ConfiguratorConfig;
+import org.apache.dubbo.rpc.cluster.configurator.parser.model.ConfigItem;
+import org.apache.dubbo.rpc.cluster.configurator.parser.model.ConfiguratorConfig;
+
import org.junit.Assert;
import org.junit.Test;
import org.yaml.snakeyaml.TypeDescription;
@@ -63,7 +63,7 @@ public class ConfigParserTest {
@Test
public void parseConfiguratorsServiceNoAppTest() throws Exception {
InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceNoApp.yml");
- List<URL> urls = ConfigParser.parseConfigurators(streamToString(yamlStream));
+ List<URL> urls = ConfigParser.parseConfigurators(streamToString(yamlStream), "serviceKey");
Assert.assertNotNull(urls);
Assert.assertEquals(2, urls.size());
URL url = urls.get(0);
@@ -74,7 +74,7 @@ public class ConfigParserTest {
@Test
public void parseConfiguratorsServiceGroupVersionTest() throws Exception {
InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceGroupVersion.yml");
- List<URL> urls = ConfigParser.parseConfigurators(streamToString(yamlStream));
+ List<URL> urls = ConfigParser.parseConfigurators(streamToString(yamlStream), "testgroup/servicekey:1.0.0");
Assert.assertNotNull(urls);
Assert.assertEquals(1, urls.size());
URL url = urls.get(0);
@@ -85,7 +85,7 @@ public class ConfigParserTest {
@Test
public void parseConfiguratorsServiceMultiAppsTest() {
InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceMultiApps.yml");
- List<URL> urls = ConfigParser.parseConfigurators(streamToString(yamlStream));
+ List<URL> urls = ConfigParser.parseConfigurators(streamToString(yamlStream), "serviceKey");
Assert.assertNotNull(urls);
Assert.assertEquals(4, urls.size());
URL url = urls.get(0);
@@ -97,29 +97,34 @@ public class ConfigParserTest {
@Test(expected = IllegalStateException.class)
public void parseConfiguratorsServiceNoRuleTest() {
InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceNoRule.yml");
- ConfigParser.parseConfigurators(streamToString(yamlStream));
+ ConfigParser.parseConfigurators(streamToString(yamlStream), "serviceKey");
Assert.fail();
}
@Test
public void parseConfiguratorsAppMultiServicesTest() {
InputStream yamlStream = this.getClass().getResourceAsStream("/AppMultiServices.yml");
- List<URL> urls = ConfigParser.parseConfigurators(streamToString(yamlStream));
+ String yamlFile = streamToString(yamlStream);
+ List<URL> urls = ConfigParser.parseConfigurators(yamlFile, "service1");
Assert.assertNotNull(urls);
- Assert.assertEquals(4, urls.size());
+ Assert.assertEquals(2, urls.size());
URL url = urls.get(0);
Assert.assertEquals("127.0.0.1", url.getAddress());
Assert.assertEquals("service1", url.getServiceInterface());
Assert.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0));
Assert.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY));
Assert.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "demo-consumer");
+
+ List<URL> urls2 = ConfigParser.parseConfigurators(yamlFile, "service-not-exist");
+ Assert.assertNotNull(urls2);
+ Assert.assertEquals(0, urls2.size());
}
@Test
public void parseConfiguratorsAppAnyServicesTest() {
InputStream yamlStream = this.getClass().getResourceAsStream("/AppAnyServices.yml");
- List<URL> urls = ConfigParser.parseConfigurators(streamToString(yamlStream));
+ List<URL> urls = ConfigParser.parseConfigurators(streamToString(yamlStream), "service1");
Assert.assertNotNull(urls);
Assert.assertEquals(2, urls.size());
URL url = urls.get(0);
@@ -133,7 +138,7 @@ public class ConfigParserTest {
@Test
public void parseConfiguratorsAppNoServiceTest() {
InputStream yamlStream = this.getClass().getResourceAsStream("/AppNoService.yml");
- List<URL> urls = ConfigParser.parseConfigurators(streamToString(yamlStream));
+ List<URL> urls = ConfigParser.parseConfigurators(streamToString(yamlStream), "service1");
Assert.assertNotNull(urls);
Assert.assertEquals(1, urls.size());
URL url = urls.get(0);
@@ -147,7 +152,7 @@ public class ConfigParserTest {
@Test
public void parseConsumerSpecificProvidersTest() {
InputStream yamlStream = this.getClass().getResourceAsStream("/ConsumerSpecificProviders.yml");
- List<URL> urls = ConfigParser.parseConfigurators(streamToString(yamlStream));
+ List<URL> urls = ConfigParser.parseConfigurators(streamToString(yamlStream), "service1");
Assert.assertNotNull(urls);
Assert.assertEquals(1, urls.size());
URL url = urls.get(0);
diff --git a/dubbo-registry/dubbo-registry-api/src/test/resources/AppAnyServices.yml b/dubbo-cluster/src/test/resources/AppAnyServices.yml
similarity index 100%
rename from dubbo-registry/dubbo-registry-api/src/test/resources/AppAnyServices.yml
rename to dubbo-cluster/src/test/resources/AppAnyServices.yml
diff --git a/dubbo-registry/dubbo-registry-api/src/test/resources/AppMultiServices.yml b/dubbo-cluster/src/test/resources/AppMultiServices.yml
similarity index 100%
rename from dubbo-registry/dubbo-registry-api/src/test/resources/AppMultiServices.yml
rename to dubbo-cluster/src/test/resources/AppMultiServices.yml
diff --git a/dubbo-registry/dubbo-registry-api/src/test/resources/AppNoService.yml b/dubbo-cluster/src/test/resources/AppNoService.yml
similarity index 100%
rename from dubbo-registry/dubbo-registry-api/src/test/resources/AppNoService.yml
rename to dubbo-cluster/src/test/resources/AppNoService.yml
diff --git a/dubbo-registry/dubbo-registry-api/src/test/resources/ConsumerSpecificProviders.yml b/dubbo-cluster/src/test/resources/ConsumerSpecificProviders.yml
similarity index 100%
rename from dubbo-registry/dubbo-registry-api/src/test/resources/ConsumerSpecificProviders.yml
rename to dubbo-cluster/src/test/resources/ConsumerSpecificProviders.yml
diff --git a/dubbo-registry/dubbo-registry-api/src/test/resources/ServiceGroupVersion.yml b/dubbo-cluster/src/test/resources/ServiceGroupVersion.yml
similarity index 100%
rename from dubbo-registry/dubbo-registry-api/src/test/resources/ServiceGroupVersion.yml
rename to dubbo-cluster/src/test/resources/ServiceGroupVersion.yml
diff --git a/dubbo-registry/dubbo-registry-api/src/test/resources/ServiceMultiApps.yml b/dubbo-cluster/src/test/resources/ServiceMultiApps.yml
similarity index 100%
rename from dubbo-registry/dubbo-registry-api/src/test/resources/ServiceMultiApps.yml
rename to dubbo-cluster/src/test/resources/ServiceMultiApps.yml
diff --git a/dubbo-registry/dubbo-registry-api/src/test/resources/ServiceNoApp.yml b/dubbo-cluster/src/test/resources/ServiceNoApp.yml
similarity index 100%
rename from dubbo-registry/dubbo-registry-api/src/test/resources/ServiceNoApp.yml
rename to dubbo-cluster/src/test/resources/ServiceNoApp.yml
diff --git a/dubbo-registry/dubbo-registry-api/src/test/resources/ServiceNoRule.yml b/dubbo-cluster/src/test/resources/ServiceNoRule.yml
similarity index 100%
rename from dubbo-registry/dubbo-registry-api/src/test/resources/ServiceNoRule.yml
rename to dubbo-cluster/src/test/resources/ServiceNoRule.yml
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 df19377..0dc71e5 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
@@ -31,7 +31,6 @@ import org.apache.dubbo.configcenter.ConfigurationListener;
import org.apache.dubbo.configcenter.DynamicConfiguration;
import org.apache.dubbo.registry.NotifyListener;
import org.apache.dubbo.registry.Registry;
-import org.apache.dubbo.registry.integration.parser.ConfigParser;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Protocol;
@@ -42,6 +41,7 @@ import org.apache.dubbo.rpc.cluster.ConfiguratorFactory;
import org.apache.dubbo.rpc.cluster.Router;
import org.apache.dubbo.rpc.cluster.RouterChain;
import org.apache.dubbo.rpc.cluster.RouterFactory;
+import org.apache.dubbo.rpc.cluster.configurator.parser.ConfigParser;
import org.apache.dubbo.rpc.cluster.directory.AbstractDirectory;
import org.apache.dubbo.rpc.cluster.directory.StaticDirectory;
import org.apache.dubbo.rpc.cluster.support.ClusterUtils;
@@ -160,12 +160,12 @@ public class RegistryDirectory<T> extends AbstractDirectory<T> implements Notify
return configurators;
}
- public static List<Configurator> configToConfiguratiors(String rawConfig) {
+ public static List<Configurator> configToConfiguratiors(String rawConfig, String serviceKey) {
if (StringUtils.isEmpty(rawConfig)) {
return new LinkedList<>();
}
try {
- List<URL> urls = ConfigParser.parseConfigurators(rawConfig);
+ List<URL> urls = ConfigParser.parseConfigurators(rawConfig, serviceKey);
return urls.stream().map(configuratorFactory::getConfigurator).collect(Collectors.toList());
} catch (Exception e) {
logger.error("Failed to parse raw dynamic config and it will not take effect, the raw config is: " + rawConfig, e);
@@ -203,6 +203,7 @@ public class RegistryDirectory<T> extends AbstractDirectory<T> implements Notify
}
String appKey = url.getParameter(Constants.APPLICATION_KEY) + Constants.CONFIGURATORS_SUFFIX;
+ dynamicConfiguration.addListener(appKey, this);
String appRawConfig = dynamicConfiguration.getConfig(appKey);
if (appRawConfig != null) {
this.process(new ConfigChangeEvent(appKey, appRawConfig));
@@ -710,6 +711,8 @@ public class RegistryDirectory<T> extends AbstractDirectory<T> implements Notify
@Override
public synchronized void process(ConfigChangeEvent event) {
+ logger.info("Notification of overriding rule, change type is: " + event.getChangeType() + ", raw config content is:\n " + event.getNewValue());
+
List<URL> urls = new ArrayList<>();
if (event.getChangeType().equals(ConfigChangeType.DELETED)) {
URL url = getConsumerUrl().clearParameters().setProtocol(Constants.EMPTY_PROTOCOL);
@@ -721,11 +724,14 @@ public class RegistryDirectory<T> extends AbstractDirectory<T> implements Notify
urls.add(url);
} else {
try {
- urls = ConfigParser.parseConfigurators(event.getNewValue());
+ urls = ConfigParser.parseConfigurators(event.getNewValue(), overrideDirectoryUrl.getServiceKey());
} catch (Exception e) {
logger.error("Failed to parse raw dynamic config and it will not take effect, the raw config is: " + event.getNewValue(), e);
}
}
+
+ logger.debug("");
+
notify(urls);
}
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 1b3aba5..2e446ce 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
@@ -35,7 +35,6 @@ import org.apache.dubbo.registry.NotifyListener;
import org.apache.dubbo.registry.Registry;
import org.apache.dubbo.registry.RegistryFactory;
import org.apache.dubbo.registry.RegistryService;
-import org.apache.dubbo.registry.integration.parser.ConfigParser;
import org.apache.dubbo.registry.support.ProviderConsumerRegTable;
import org.apache.dubbo.registry.support.ProviderInvokerWrapper;
import org.apache.dubbo.rpc.Exporter;
@@ -45,6 +44,7 @@ import org.apache.dubbo.rpc.ProxyFactory;
import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.cluster.Cluster;
import org.apache.dubbo.rpc.cluster.Configurator;
+import org.apache.dubbo.rpc.cluster.configurator.parser.ConfigParser;
import org.apache.dubbo.rpc.protocol.InvokerWrapper;
import java.util.ArrayList;
@@ -160,29 +160,34 @@ public class RegistryProtocol implements Protocol {
final OverrideListener overrideSubscribeListener = new OverrideListener(overrideSubscribeUrl, originInvoker);
overrideListeners.put(overrideSubscribeUrl, overrideSubscribeListener);
- providerUrl = overrideUrlWithConfig(providerUrl);
- //export invoker
- final ExporterChangeableWrapper<T> exporter = doLocalExport(originInvoker, providerUrl);
-
- // url to registry
- final Registry registry = getRegistry(originInvoker);
- final URL registeredProviderUrl = getRegistedProviderUrl(providerUrl, registryUrl);
- ProviderConsumerRegTable.registerProvider(originInvoker, registryUrl, registeredProviderUrl);
- //to judge if we need to delay publish
- boolean register = registeredProviderUrl.getParameter("register", true);
- if (register) {
- register(registryUrl, registeredProviderUrl);
- ProviderConsumerRegTable.getProviderWrapper(originInvoker).setReg(true);
- }
+ /**
+ * synchronized is used to make sure override notifications come after export and register finished.
+ * we will eagerly call dynamicConfiguration.getConfig() to let existing overrides take effect before export or register.
+ */
+ synchronized (overrideSubscribeListener) {
+ providerUrl = overrideUrlWithConfig(providerUrl, overrideSubscribeListener);
+ //export invoker
+ final ExporterChangeableWrapper<T> exporter = doLocalExport(originInvoker, providerUrl);
+
+ // url to registry
+ final Registry registry = getRegistry(originInvoker);
+ final URL registeredProviderUrl = getRegistedProviderUrl(providerUrl, registryUrl);
+ ProviderConsumerRegTable.registerProvider(originInvoker, registryUrl, registeredProviderUrl);
+ //to judge if we need to delay publish
+ boolean register = registeredProviderUrl.getParameter("register", true);
+ if (register) {
+ register(registryUrl, registeredProviderUrl);
+ ProviderConsumerRegTable.getProviderWrapper(originInvoker).setReg(true);
+ }
- // Deprecated! Subscribe to override rules in 2.6.x or before.
- registry.subscribe(overrideSubscribeUrl, overrideSubscribeListener);
- subscribeDynamicConfiguration(overrideSubscribeUrl);
+ // Deprecated! Subscribe to override rules in 2.6.x or before.
+ registry.subscribe(overrideSubscribeUrl, overrideSubscribeListener);
- exporter.setRegisterUrl(registeredProviderUrl);
- exporter.setSubscribeUrl(overrideSubscribeUrl);
- //Ensure that a new exporter instance is returned every time export
- return new DestroyableExporter<>(exporter);
+ exporter.setRegisterUrl(registeredProviderUrl);
+ exporter.setSubscribeUrl(overrideSubscribeUrl);
+ //Ensure that a new exporter instance is returned every time export
+ return new DestroyableExporter<>(exporter);
+ }
}
/**
@@ -192,42 +197,27 @@ public class RegistryProtocol implements Protocol {
* @param <T>
* @return
*/
- private <T> URL overrideUrlWithConfig(URL providerUrl) {
+ private <T> URL overrideUrlWithConfig(URL providerUrl, OverrideListener listener) {
List<Configurator> configurators = new LinkedList<>();
- String appRawConfig = dynamicConfiguration.getConfig(providerUrl.getParameter(Constants.APPLICATION_KEY) + Constants.CONFIGURATORS_SUFFIX);
+ String appKey = providerUrl.getParameter(Constants.APPLICATION_KEY) + Constants.CONFIGURATORS_SUFFIX;
+ dynamicConfiguration.addListener(appKey, listener);
+ String appRawConfig = dynamicConfiguration.getConfig(appKey);
if (!StringUtils.isEmpty(appRawConfig)) {
- List<Configurator> appDynamicConfigurators = RegistryDirectory.configToConfiguratiors(appRawConfig);
+ List<Configurator> appDynamicConfigurators = RegistryDirectory.configToConfiguratiors(appRawConfig, providerUrl.getServiceKey());
configurators.addAll(appDynamicConfigurators);
}
- String rawConfig = dynamicConfiguration.getConfig(providerUrl.getEncodedServiceKey() + Constants.CONFIGURATORS_SUFFIX);
+
+ String serviceKey = providerUrl.getEncodedServiceKey() + Constants.CONFIGURATORS_SUFFIX;
+ dynamicConfiguration.addListener(serviceKey, listener);
+ String rawConfig = dynamicConfiguration.getConfig(serviceKey);
if (!StringUtils.isEmpty(rawConfig)) {
- List<Configurator> dynamicConfigurators = RegistryDirectory.configToConfiguratiors(rawConfig);
+ List<Configurator> dynamicConfigurators = RegistryDirectory.configToConfiguratiors(rawConfig, providerUrl.getServiceKey());
configurators.addAll(dynamicConfigurators);
}
providerUrl = getConfigedInvokerUrl(configurators, providerUrl);
return providerUrl;
}
- private void subscribeDynamicConfiguration(URL url) {
- synchronized (overrideListeners.get(url)) {
- OverrideListener listener = (OverrideListener) overrideListeners.get(url);
-
- String appKey = url.getParameter(Constants.APPLICATION_KEY) + Constants.CONFIGURATORS_SUFFIX;
- dynamicConfiguration.addListener(appKey, listener);
- String appRawConfig = dynamicConfiguration.getConfig(appKey);
- if (appRawConfig != null) {
- listener.process(new ConfigChangeEvent(appKey, appRawConfig));
- }
-
- String serviceKey = url.getEncodedServiceKey() + Constants.CONFIGURATORS_SUFFIX;
- dynamicConfiguration.addListener(serviceKey, listener);
- String rawConfig = dynamicConfiguration.getConfig(serviceKey);
- if (rawConfig != null) {
- listener.process(new ConfigChangeEvent(serviceKey, rawConfig));
- }
- }
- }
-
@SuppressWarnings("unchecked")
private <T> ExporterChangeableWrapper<T> doLocalExport(final Invoker<T> originInvoker, URL providerUrl) {
String key = getCacheKey(originInvoker);
@@ -502,14 +492,6 @@ public class RegistryProtocol implements Protocol {
this.originInvoker = originalInvoker;
}
- public void setDynamicConfigurators(List<Configurator> dynamicConfigurators) {
- this.dynamicConfigurators = dynamicConfigurators;
- }
-
- public void setAppDynamicConfigurators(List<Configurator> appDynamicConfigurators) {
- this.appDynamicConfigurators = appDynamicConfigurators;
- }
-
/**
* @param urls The list of registered information , is always not empty, The meaning is the same as the return value of {@link org.apache.dubbo.registry.RegistryService#lookup(URL)}.
*/
@@ -600,7 +582,7 @@ public class RegistryProtocol implements Protocol {
} else {
try {
// parseConfigurators will recognize app/service config automatically.
- urls = ConfigParser.parseConfigurators(event.getNewValue());
+ urls = ConfigParser.parseConfigurators(event.getNewValue(), subscribeUrl.getServiceKey());
} catch (Exception e) {
logger.error("Failed to parse raw dynamic config and it will not take effect, the raw config is: " + event.getNewValue(), e);
return;