This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.0 by this push:
     new 7ad1574  fix migration rule listener when config center is not set
7ad1574 is described below

commit 7ad1574c2c28a036cd980b52d274d20d59ef3f92
Author: ken.lj <[email protected]>
AuthorDate: Tue Nov 24 14:12:44 2020 +0800

    fix migration rule listener when config center is not set
---
 .../client/migration/MigrationRuleListener.java       | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git 
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationRuleListener.java
 
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationRuleListener.java
index da604c9..c667376 100644
--- 
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationRuleListener.java
+++ 
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationRuleListener.java
@@ -49,12 +49,19 @@ public class MigrationRuleListener implements 
RegistryProtocolListener, Configur
 
     public MigrationRuleListener() {
         this.configuration = 
ApplicationModel.getEnvironment().getDynamicConfiguration().orElse(null);
-
-        logger.info("Listening for migration rules on dataId-" + RULE_KEY + " 
group-" + DUBBO_SERVICEDISCOVERY_MIGRATION);
-        configuration.addListener(RULE_KEY, DUBBO_SERVICEDISCOVERY_MIGRATION, 
this);
-
-        String rawRule = configuration.getConfig(RULE_KEY, 
DUBBO_SERVICEDISCOVERY_MIGRATION);
-        if (StringUtils.isEmpty(rawRule)) {
+        if (this.configuration != null) {
+            logger.info("Listening for migration rules on dataId " + RULE_KEY 
+ ", group " + DUBBO_SERVICEDISCOVERY_MIGRATION);
+            configuration.addListener(RULE_KEY, 
DUBBO_SERVICEDISCOVERY_MIGRATION, this);
+
+            String rawRule = configuration.getConfig(RULE_KEY, 
DUBBO_SERVICEDISCOVERY_MIGRATION);
+            if (StringUtils.isEmpty(rawRule)) {
+                rawRule = INIT;
+            }
+            this.rawRule = rawRule;
+        } else {
+            if (logger.isWarnEnabled()) {
+                logger.warn("Using default configuration rule because config 
center is not configured!");
+            }
             rawRule = INIT;
         }
         process(new ConfigChangedEvent(RULE_KEY, 
DUBBO_SERVICEDISCOVERY_MIGRATION, rawRule));

Reply via email to