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

victory pushed a commit to branch cloud-native
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/cloud-native by this push:
     new dd360f4  metadata support for nacos, consul, etcd
dd360f4 is described below

commit dd360f4f858922f9ca4c068ce8c07b9ba823a56b
Author: cvictory <shenglic...@gmail.com>
AuthorDate: Thu Aug 15 11:23:30 2019 +0800

    metadata support for nacos, consul, etcd
---
 .../BaseApplicationMetadataIdentifier.java         |  4 +-
 .../report/identifier/BaseMetadataIdentifier.java  | 12 ++++
 .../identifier/BaseServiceMetadataIdentifier.java  |  4 +-
 .../metadata/report/identifier/KeyTypeEnum.java    |  8 +++
 .../report/identifier/MetadataIdentifier.java      |  8 +--
 .../identifier/ServiceMetadataIdentifier.java      |  5 +-
 .../identifier/SubscriberMetadataIdentifier.java   |  5 +-
 .../report/support/AbstractMetadataReport.java     |  5 +-
 .../RemoteWritableMetadataServiceDelegate.java     | 42 +++++------
 .../report/identifier/MetadataIdentifierTest.java  |  4 +-
 .../report/support/AbstractMetadataReportTest.java | 21 +++---
 .../metadata/test/JTestMetadataReport4Test.java    |  9 +--
 .../store/consul/ConsulMetadataReport.java         | 55 +++++++++++---
 .../metadata/store/etcd/EtcdMetadataReport.java    | 28 ++++++--
 .../metadata/store/nacos/NacosMetadataReport.java  | 48 ++++++++++---
 .../store/nacos/NacosMetadataReportTest.java       |  5 +-
 .../metadata/store/redis/RedisMetadataReport.java  | 84 +++++++++++++++++++---
 .../store/redis/RedisMetadataReportTest.java       |  9 +--
 .../store/zookeeper/ZookeeperMetadataReport.java   | 23 +++---
 .../zookeeper/ZookeeperMetadataReportTest.java     |  3 +-
 20 files changed, 270 insertions(+), 112 deletions(-)

diff --git 
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/BaseApplicationMetadataIdentifier.java
 
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/BaseApplicationMetadataIdentifier.java
index 7844e64..741d4da 100644
--- 
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/BaseApplicationMetadataIdentifier.java
+++ 
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/BaseApplicationMetadataIdentifier.java
@@ -12,8 +12,8 @@ import static 
org.apache.dubbo.metadata.MetadataConstants.KEY_SEPARATOR;
 public class BaseApplicationMetadataIdentifier {
     String application;
 
-    String getUniqueKey(MetadataIdentifier.KeyTypeEnum keyType, String... 
params) {
-        if (keyType == MetadataIdentifier.KeyTypeEnum.PATH) {
+    String getUniqueKey(KeyTypeEnum keyType, String... params) {
+        if (keyType == KeyTypeEnum.PATH) {
             return getFilePathKey(params);
         }
         return getIdentifierKey(params);
diff --git 
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/BaseMetadataIdentifier.java
 
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/BaseMetadataIdentifier.java
new file mode 100644
index 0000000..5cb1b78
--- /dev/null
+++ 
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/BaseMetadataIdentifier.java
@@ -0,0 +1,12 @@
+package org.apache.dubbo.metadata.report.identifier;
+
+/**
+ * @author cvictory ON 2019-08-15
+ */
+public interface BaseMetadataIdentifier {
+
+    String getUniqueKey(KeyTypeEnum keyType);
+
+    String getIdentifierKey();
+
+}
diff --git 
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/BaseServiceMetadataIdentifier.java
 
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/BaseServiceMetadataIdentifier.java
index f4d9999..81edc13 100644
--- 
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/BaseServiceMetadataIdentifier.java
+++ 
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/BaseServiceMetadataIdentifier.java
@@ -19,8 +19,8 @@ public class BaseServiceMetadataIdentifier {
     String group;
     String side;
 
-    String getUniqueKey(MetadataIdentifier.KeyTypeEnum keyType, String... 
params) {
-        if (keyType == MetadataIdentifier.KeyTypeEnum.PATH) {
+    String getUniqueKey(KeyTypeEnum keyType, String... params) {
+        if (keyType == KeyTypeEnum.PATH) {
             return getFilePathKey(params);
         }
         return getIdentifierKey(params);
diff --git 
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/KeyTypeEnum.java
 
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/KeyTypeEnum.java
new file mode 100644
index 0000000..41069aa
--- /dev/null
+++ 
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/KeyTypeEnum.java
@@ -0,0 +1,8 @@
+package org.apache.dubbo.metadata.report.identifier;
+
+/**
+ * 2019-08-15
+ */
+public enum KeyTypeEnum {
+    PATH, UNIQUE_KEY
+}
diff --git 
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/MetadataIdentifier.java
 
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/MetadataIdentifier.java
index 335e3f0..ce7542f 100644
--- 
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/MetadataIdentifier.java
+++ 
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/MetadataIdentifier.java
@@ -22,14 +22,15 @@ import static 
org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY;
 import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
 import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY;
 import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
-import static org.apache.dubbo.metadata.MetadataConstants.KEY_SEPARATOR;
 
 /**
  * The MetadataIdentifier is used to store method descriptor.
  * <p>
+ * The name of class is reserved because of it has been used in the previous 
version.
+ * <p>
  * 2018/10/25
  */
-public class MetadataIdentifier extends BaseServiceMetadataIdentifier {
+public class MetadataIdentifier extends BaseServiceMetadataIdentifier 
implements BaseMetadataIdentifier {
 
     private String application;
 
@@ -101,7 +102,4 @@ public class MetadataIdentifier extends 
BaseServiceMetadataIdentifier {
         this.application = application;
     }
 
-    public enum KeyTypeEnum {
-        PATH, UNIQUE_KEY
-    }
 }
diff --git 
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/ServiceMetadataIdentifier.java
 
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/ServiceMetadataIdentifier.java
index 65c7b4e..a8cd55b 100644
--- 
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/ServiceMetadataIdentifier.java
+++ 
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/ServiceMetadataIdentifier.java
@@ -3,7 +3,6 @@ package org.apache.dubbo.metadata.report.identifier;
 import org.apache.dubbo.common.URL;
 
 import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
-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.CommonConstants.VERSION_KEY;
 import static org.apache.dubbo.metadata.MetadataConstants.KEY_REVISON_PREFIX;
@@ -14,7 +13,7 @@ import static 
org.apache.dubbo.metadata.MetadataConstants.KEY_REVISON_PREFIX;
  * <p>
  * 2019-08-09
  */
-public class ServiceMetadataIdentifier extends BaseServiceMetadataIdentifier {
+public class ServiceMetadataIdentifier extends BaseServiceMetadataIdentifier 
implements BaseMetadataIdentifier {
 
     private String revision;
     private String protocol;
@@ -40,7 +39,7 @@ public class ServiceMetadataIdentifier extends 
BaseServiceMetadataIdentifier {
         this.protocol = url.getProtocol();
     }
 
-    public String getUniqueKey(MetadataIdentifier.KeyTypeEnum keyType) {
+    public String getUniqueKey(KeyTypeEnum keyType) {
         return super.getUniqueKey(keyType, protocol, KEY_REVISON_PREFIX + 
revision);
     }
 
diff --git 
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/SubscriberMetadataIdentifier.java
 
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/SubscriberMetadataIdentifier.java
index a227f1e..69bed30 100644
--- 
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/SubscriberMetadataIdentifier.java
+++ 
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/SubscriberMetadataIdentifier.java
@@ -6,10 +6,9 @@ import static 
org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY;
 import static org.apache.dubbo.common.constants.CommonConstants.REVISION_KEY;
 
 /**
- *
  * 2019-08-12
  */
-public class SubscriberMetadataIdentifier extends 
BaseApplicationMetadataIdentifier{
+public class SubscriberMetadataIdentifier extends 
BaseApplicationMetadataIdentifier implements BaseMetadataIdentifier {
 
     private String revision;
 
@@ -27,7 +26,7 @@ public class SubscriberMetadataIdentifier extends 
BaseApplicationMetadataIdentif
         this.revision = url.getParameter(REVISION_KEY, "");
     }
 
-    public String getUniqueKey(MetadataIdentifier.KeyTypeEnum keyType) {
+    public String getUniqueKey(KeyTypeEnum keyType) {
         return super.getUniqueKey(keyType, revision);
     }
 
diff --git 
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReport.java
 
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReport.java
index 7f46eef..71f7532 100644
--- 
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReport.java
+++ 
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReport.java
@@ -25,6 +25,7 @@ import org.apache.dubbo.common.utils.NamedThreadFactory;
 import org.apache.dubbo.metadata.definition.model.FullServiceDefinition;
 import org.apache.dubbo.metadata.definition.model.ServiceDefinition;
 import org.apache.dubbo.metadata.report.MetadataReport;
+import org.apache.dubbo.metadata.report.identifier.KeyTypeEnum;
 import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier;
 import org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier;
 import 
org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier;
@@ -200,9 +201,9 @@ public abstract class AbstractMetadataReport implements 
MetadataReport {
 
         try {
             if (add) {
-                
properties.setProperty(metadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY),
 value);
+                
properties.setProperty(metadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), 
value);
             } else {
-                
properties.remove(metadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY));
+                
properties.remove(metadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY));
             }
             long version = lastCacheChanged.incrementAndGet();
             if (sync) {
diff --git 
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/store/RemoteWritableMetadataServiceDelegate.java
 
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/store/RemoteWritableMetadataServiceDelegate.java
index 3885429..f46bf21 100644
--- 
a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/store/RemoteWritableMetadataServiceDelegate.java
+++ 
b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/store/RemoteWritableMetadataServiceDelegate.java
@@ -3,8 +3,6 @@ package org.apache.dubbo.metadata.store;
 import org.apache.dubbo.common.URL;
 import org.apache.dubbo.metadata.WritableMetadataService;
 
-import java.util.ArrayList;
-import java.util.List;
 import java.util.SortedSet;
 import java.util.function.BiFunction;
 
@@ -14,20 +12,16 @@ import java.util.function.BiFunction;
  * @since 2.7.5
  */
 public class RemoteWritableMetadataServiceDelegate implements 
WritableMetadataService {
-    List<WritableMetadataService> metadataServiceList = new ArrayList<>(2);
+    private WritableMetadataService defaultWritableMetadataService;
+    private RemoteWritableMetadataService remoteWritableMetadataService;
 
     public RemoteWritableMetadataServiceDelegate() {
-        metadataServiceList.add(WritableMetadataService.getDefaultExtension());
-        metadataServiceList.add(new RemoteWritableMetadataService());
+        defaultWritableMetadataService = 
WritableMetadataService.getDefaultExtension();
+        remoteWritableMetadataService = new RemoteWritableMetadataService();
     }
 
-    private WritableMetadataService getInMemoryWritableMetadataService() {
-        for (WritableMetadataService writableMetadataService : 
metadataServiceList) {
-            if (writableMetadataService instanceof 
InMemoryWritableMetadataService) {
-                return writableMetadataService;
-            }
-        }
-        return metadataServiceList.get(0);
+    private WritableMetadataService getDefaultWritableMetadataService() {
+        return defaultWritableMetadataService;
     }
 
     @Override
@@ -53,43 +47,41 @@ public class RemoteWritableMetadataServiceDelegate 
implements WritableMetadataSe
     @Override
     public boolean refreshMetadata(String exportedRevision, String 
subscribedRevision) {
         boolean result = true;
-        for (WritableMetadataService writableMetadataService : 
metadataServiceList) {
-            result &= 
writableMetadataService.refreshMetadata(exportedRevision, subscribedRevision);
-        }
+        result &= 
defaultWritableMetadataService.refreshMetadata(exportedRevision, 
subscribedRevision);
+        result &= 
remoteWritableMetadataService.refreshMetadata(exportedRevision, 
subscribedRevision);
         return result;
     }
 
     @Override
     public void publishServiceDefinition(URL providerUrl) {
-        for (WritableMetadataService writableMetadataService : 
metadataServiceList) {
-            writableMetadataService.publishServiceDefinition(providerUrl);
-        }
+        defaultWritableMetadataService.publishServiceDefinition(providerUrl);
+        remoteWritableMetadataService.publishServiceDefinition(providerUrl);
     }
 
     @Override
     public SortedSet<String> getExportedURLs(String serviceInterface, String 
group, String version, String protocol) {
-        return 
getInMemoryWritableMetadataService().getExportedURLs(serviceInterface, group, 
version, protocol);
+        return 
getDefaultWritableMetadataService().getExportedURLs(serviceInterface, group, 
version, protocol);
     }
+
     @Override
     public SortedSet<String> getSubscribedURLs() {
-        return getInMemoryWritableMetadataService().getSubscribedURLs();
+        return getDefaultWritableMetadataService().getSubscribedURLs();
     }
 
     @Override
     public String getServiceDefinition(String interfaceName, String version, 
String group) {
-        return 
getInMemoryWritableMetadataService().getServiceDefinition(interfaceName, 
version, group);
+        return 
getDefaultWritableMetadataService().getServiceDefinition(interfaceName, 
version, group);
     }
 
     @Override
     public String getServiceDefinition(String serviceKey) {
-        return 
getInMemoryWritableMetadataService().getServiceDefinition(serviceKey);
+        return 
getDefaultWritableMetadataService().getServiceDefinition(serviceKey);
     }
 
     private boolean doFunction(BiFunction<WritableMetadataService, URL, 
Boolean> func, URL url) {
         boolean result = true;
-        for (WritableMetadataService writableMetadataService : 
metadataServiceList) {
-            result &= func.apply(writableMetadataService, url);
-        }
+        result &= func.apply(defaultWritableMetadataService, url);
+        result &= func.apply(remoteWritableMetadataService, url);
         return result;
     }
 }
diff --git 
a/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/identifier/MetadataIdentifierTest.java
 
b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/identifier/MetadataIdentifierTest.java
index cb19880..90df3db 100644
--- 
a/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/identifier/MetadataIdentifierTest.java
+++ 
b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/identifier/MetadataIdentifierTest.java
@@ -17,7 +17,7 @@
 package org.apache.dubbo.metadata.report.identifier;
 
 import org.apache.dubbo.metadata.MetadataConstants;
-import 
org.apache.dubbo.metadata.report.identifier.MetadataIdentifier.KeyTypeEnum;
+import org.apache.dubbo.metadata.report.identifier.KeyTypeEnum;
 
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
@@ -42,7 +42,7 @@ public class MetadataIdentifierTest {
                         (version == null ? "" : (version + PATH_SEPARATOR))
                         + (group == null ? "" : (group + PATH_SEPARATOR)) + 
PROVIDER_SIDE
                         + PATH_SEPARATOR + application);
-        
Assertions.assertEquals(providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY),
+        
Assertions.assertEquals(providerMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY),
                 interfaceName + MetadataConstants.KEY_SEPARATOR +
                         (version == null ? "" : version) + 
MetadataConstants.KEY_SEPARATOR
                         + (group == null ? "" : group) + 
MetadataConstants.KEY_SEPARATOR
diff --git 
a/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReportTest.java
 
b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReportTest.java
index 24239e5..9d4267f 100644
--- 
a/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReportTest.java
+++ 
b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReportTest.java
@@ -20,6 +20,7 @@ import org.apache.dubbo.common.URL;
 import org.apache.dubbo.common.utils.NetUtils;
 import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder;
 import org.apache.dubbo.metadata.definition.model.FullServiceDefinition;
+import org.apache.dubbo.metadata.report.identifier.KeyTypeEnum;
 import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier;
 import org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier;
 import 
org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier;
@@ -72,7 +73,7 @@ public class AbstractMetadataReportTest {
         String application = "vic";
         MetadataIdentifier providerMetadataIdentifier = 
storePrivider(abstractMetadataReport, interfaceName, version, group, 
application);
         Thread.sleep(1500);
-        
Assertions.assertNotNull(abstractMetadataReport.store.get(providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY)));
+        
Assertions.assertNotNull(abstractMetadataReport.store.get(providerMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY)));
     }
 
     @Test
@@ -83,7 +84,7 @@ public class AbstractMetadataReportTest {
         String application = "vic";
         abstractMetadataReport.syncReport = true;
         MetadataIdentifier providerMetadataIdentifier = 
storePrivider(abstractMetadataReport, interfaceName, version, group, 
application);
-        
Assertions.assertNotNull(abstractMetadataReport.store.get(providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY)));
+        
Assertions.assertNotNull(abstractMetadataReport.store.get(providerMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY)));
     }
 
     @Test
@@ -102,7 +103,7 @@ public class AbstractMetadataReportTest {
 
         Thread.sleep(2000);
         Assertions.assertTrue(singleMetadataReport.file.exists());
-        
Assertions.assertTrue(singleMetadataReport.properties.containsKey(providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY)));
+        
Assertions.assertTrue(singleMetadataReport.properties.containsKey(providerMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY)));
     }
 
     @Test
@@ -221,17 +222,17 @@ public class AbstractMetadataReportTest {
 
         Assertions.assertEquals(3, abstractMetadataReport.store.size());
 
-        String v = 
abstractMetadataReport.store.get(providerMetadataIdentifier1.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY));
+        String v = 
abstractMetadataReport.store.get(providerMetadataIdentifier1.getUniqueKey(KeyTypeEnum.UNIQUE_KEY));
         Gson gson = new Gson();
         FullServiceDefinition data = gson.fromJson(v, 
FullServiceDefinition.class);
         checkParam(data.getParameters(), application, version);
 
-        String v2 = 
abstractMetadataReport.store.get(providerMetadataIdentifier2.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY));
+        String v2 = 
abstractMetadataReport.store.get(providerMetadataIdentifier2.getUniqueKey(KeyTypeEnum.UNIQUE_KEY));
         gson = new Gson();
         data = gson.fromJson(v2, FullServiceDefinition.class);
         checkParam(data.getParameters(), application, version + "_2");
 
-        String v3 = 
abstractMetadataReport.store.get(consumerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY));
+        String v3 = 
abstractMetadataReport.store.get(consumerMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY));
         gson = new Gson();
         Map v3Map = gson.fromJson(v3, Map.class);
         checkParam(v3Map, application, version + "_3");
@@ -283,12 +284,12 @@ public class AbstractMetadataReportTest {
 
         @Override
         protected void doStoreProviderMetadata(MetadataIdentifier 
providerMetadataIdentifier, String serviceDefinitions) {
-            
store.put(providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY),
 serviceDefinitions);
+            
store.put(providerMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), 
serviceDefinitions);
         }
 
         @Override
         protected void doStoreConsumerMetadata(MetadataIdentifier 
consumerMetadataIdentifier, String serviceParameterString) {
-            
store.put(consumerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY),
 serviceParameterString);
+            
store.put(consumerMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), 
serviceParameterString);
         }
 
         @Override
@@ -340,7 +341,7 @@ public class AbstractMetadataReportTest {
             if (executeTimes <= needRetryTimes) {
                 throw new RuntimeException("must retry:" + executeTimes);
             }
-            
store.put(providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY),
 serviceDefinitions);
+            
store.put(providerMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), 
serviceDefinitions);
         }
 
         @Override
@@ -349,7 +350,7 @@ public class AbstractMetadataReportTest {
             if (executeTimes <= needRetryTimes) {
                 throw new RuntimeException("must retry:" + executeTimes);
             }
-            
store.put(consumerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY),
 serviceParameterString);
+            
store.put(consumerMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), 
serviceParameterString);
         }
 
         @Override
diff --git 
a/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/test/JTestMetadataReport4Test.java
 
b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/test/JTestMetadataReport4Test.java
index 57d41ee..dc1571f 100644
--- 
a/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/test/JTestMetadataReport4Test.java
+++ 
b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/test/JTestMetadataReport4Test.java
@@ -19,6 +19,7 @@ package org.apache.dubbo.metadata.test;
 import org.apache.dubbo.common.URL;
 import org.apache.dubbo.common.logger.Logger;
 import org.apache.dubbo.common.logger.LoggerFactory;
+import org.apache.dubbo.metadata.report.identifier.KeyTypeEnum;
 import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier;
 import org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier;
 import 
org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier;
@@ -53,12 +54,12 @@ public class JTestMetadataReport4Test extends 
AbstractMetadataReport {
 
     @Override
     protected void doStoreProviderMetadata(MetadataIdentifier 
providerMetadataIdentifier, String serviceDefinitions) {
-        
store.put(providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY),
 serviceDefinitions);
+        
store.put(providerMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), 
serviceDefinitions);
     }
 
     @Override
     protected void doStoreConsumerMetadata(MetadataIdentifier 
consumerMetadataIdentifier, String serviceParameterString) {
-        
store.put(consumerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY),
 serviceParameterString);
+        
store.put(consumerMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), 
serviceParameterString);
     }
 
     @Override
@@ -87,11 +88,11 @@ public class JTestMetadataReport4Test extends 
AbstractMetadataReport {
     }
 
     public static String getProviderKey(URL url) {
-        return new 
MetadataIdentifier(url).getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY);
+        return new 
MetadataIdentifier(url).getUniqueKey(KeyTypeEnum.UNIQUE_KEY);
     }
 
     public static String getConsumerKey(URL url) {
-        return new 
MetadataIdentifier(url).getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY);
+        return new 
MetadataIdentifier(url).getUniqueKey(KeyTypeEnum.UNIQUE_KEY);
     }
 
     @Override
diff --git 
a/dubbo-metadata/dubbo-metadata-report-consul/src/main/java/org/apache/dubbo/metadata/store/consul/ConsulMetadataReport.java
 
b/dubbo-metadata/dubbo-metadata-report-consul/src/main/java/org/apache/dubbo/metadata/store/consul/ConsulMetadataReport.java
index ba96a08..c1e0a30 100644
--- 
a/dubbo-metadata/dubbo-metadata-report-consul/src/main/java/org/apache/dubbo/metadata/store/consul/ConsulMetadataReport.java
+++ 
b/dubbo-metadata/dubbo-metadata-report-consul/src/main/java/org/apache/dubbo/metadata/store/consul/ConsulMetadataReport.java
@@ -20,6 +20,9 @@ package org.apache.dubbo.metadata.store.consul;
 import org.apache.dubbo.common.URL;
 import org.apache.dubbo.common.logger.Logger;
 import org.apache.dubbo.common.logger.LoggerFactory;
+import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.metadata.report.identifier.BaseMetadataIdentifier;
+import org.apache.dubbo.metadata.report.identifier.KeyTypeEnum;
 import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier;
 import org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier;
 import 
org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier;
@@ -27,7 +30,12 @@ import 
org.apache.dubbo.metadata.report.support.AbstractMetadataReport;
 import org.apache.dubbo.rpc.RpcException;
 
 import com.ecwid.consul.v1.ConsulClient;
+import com.ecwid.consul.v1.Response;
+import com.ecwid.consul.v1.kv.model.GetValue;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 
 /**
@@ -59,40 +67,69 @@ public class ConsulMetadataReport extends 
AbstractMetadataReport {
 
     @Override
     protected void doSaveMetadata(ServiceMetadataIdentifier 
serviceMetadataIdentifier, URL url) {
-        throw new UnsupportedOperationException("This extension does not 
support working as a remote metadata center.");
+        this.storeMetadata(serviceMetadataIdentifier, 
URL.encode(url.toFullString()));
     }
 
     @Override
     protected void doRemoveMetadata(ServiceMetadataIdentifier 
serviceMetadataIdentifier) {
-        throw new UnsupportedOperationException("This extension does not 
support working as a remote metadata center.");
+        this.deleteMetadata(serviceMetadataIdentifier);
     }
 
     @Override
     protected List<String> doGetExportedURLs(ServiceMetadataIdentifier 
metadataIdentifier) {
-        throw new UnsupportedOperationException("This extension does not 
support working as a remote metadata center.");
+        //todo encode and decode
+        String content = getMetadata(metadataIdentifier);
+        if (StringUtils.isEmpty(content)) {
+            return Collections.emptyList();
+        }
+        return new ArrayList<String>(Arrays.asList(URL.decode(content)));
     }
 
     @Override
     protected void doSaveSubscriberData(SubscriberMetadataIdentifier 
subscriberMetadataIdentifier, String urlListStr) {
-
+        this.storeMetadata(subscriberMetadataIdentifier, urlListStr);
     }
 
     @Override
     protected String doGetSubscribedURLs(SubscriberMetadataIdentifier 
subscriberMetadataIdentifier) {
-        throw new UnsupportedOperationException("This extension does not 
support working as a remote metadata center.");
+        return getMetadata(subscriberMetadataIdentifier);
     }
 
-    private void storeMetadata(MetadataIdentifier identifier, String v) {
+    private void storeMetadata(BaseMetadataIdentifier identifier, String v) {
         try {
-            
client.setKVValue(identifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY),
 v);
+            client.setKVValue(identifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), 
v);
         } catch (Throwable t) {
             logger.error("Failed to put " + identifier + " to consul " + v + 
", cause: " + t.getMessage(), t);
             throw new RpcException("Failed to put " + identifier + " to consul 
" + v + ", cause: " + t.getMessage(), t);
         }
     }
 
+    private void deleteMetadata(BaseMetadataIdentifier identifier) {
+        try {
+            
client.deleteKVValue(identifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY));
+        } catch (Throwable t) {
+            logger.error("Failed to delete " + identifier + " from consul , 
cause: " + t.getMessage(), t);
+            throw new RpcException("Failed to delete " + identifier + " from 
consul , cause: " + t.getMessage(), t);
+        }
+    }
+
+    private String getMetadata(BaseMetadataIdentifier identifier) {
+        try {
+            Response<GetValue> value = 
client.getKVValue(identifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY));
+            //FIXME CHECK
+            if (value != null && value.getValue() != null) {
+                //todo check decode value and value diff
+                return value.getValue().getValue();
+            }
+            return null;
+        } catch (Throwable t) {
+            logger.error("Failed to get " + identifier + " from consul , 
cause: " + t.getMessage(), t);
+            throw new RpcException("Failed to get " + identifier + " from 
consul , cause: " + t.getMessage(), t);
+        }
+    }
+
     @Override
-    public String getServiceDefinition(MetadataIdentifier 
consumerMetadataIdentifier) {
-        throw new UnsupportedOperationException("This extension does not 
support working as a remote metadata center.");
+    public String getServiceDefinition(MetadataIdentifier metadataIdentifier) {
+        return getMetadata(metadataIdentifier);
     }
 }
diff --git 
a/dubbo-metadata/dubbo-metadata-report-etcd/src/main/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReport.java
 
b/dubbo-metadata/dubbo-metadata-report-etcd/src/main/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReport.java
index 507cd53..1e97927 100644
--- 
a/dubbo-metadata/dubbo-metadata-report-etcd/src/main/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReport.java
+++ 
b/dubbo-metadata/dubbo-metadata-report-etcd/src/main/java/org/apache/dubbo/metadata/store/etcd/EtcdMetadataReport.java
@@ -36,12 +36,18 @@ package org.apache.dubbo.metadata.store.etcd;
 import org.apache.dubbo.common.URL;
 import org.apache.dubbo.common.logger.Logger;
 import org.apache.dubbo.common.logger.LoggerFactory;
+import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.metadata.report.identifier.BaseMetadataIdentifier;
+import org.apache.dubbo.metadata.report.identifier.KeyTypeEnum;
 import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier;
 import org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier;
 import 
org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier;
 import org.apache.dubbo.metadata.report.support.AbstractMetadataReport;
 import org.apache.dubbo.remoting.etcd.jetcd.JEtcdClient;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 
 import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
@@ -86,22 +92,32 @@ public class EtcdMetadataReport extends 
AbstractMetadataReport {
 
     @Override
     protected void doSaveMetadata(ServiceMetadataIdentifier 
serviceMetadataIdentifier, URL url) {
-        throw new UnsupportedOperationException("This extension does not 
support working as a remote metadata center.");
+        String key = getNodeKey(serviceMetadataIdentifier);
+        if (!etcdClient.put(key, URL.encode(url.toFullString()))) {
+            logger.error("Failed to put " + serviceMetadataIdentifier + " to 
etcd, value: " + url);
+        }
     }
 
     @Override
     protected void doRemoveMetadata(ServiceMetadataIdentifier 
serviceMetadataIdentifier) {
-        throw new UnsupportedOperationException("This extension does not 
support working as a remote metadata center.");
+        etcdClient.delete(getNodeKey(serviceMetadataIdentifier));
     }
 
     @Override
     protected List<String> doGetExportedURLs(ServiceMetadataIdentifier 
metadataIdentifier) {
-        throw new UnsupportedOperationException("This extension does not 
support working as a remote metadata center.");
+        String content = etcdClient.getKVValue(getNodeKey(metadataIdentifier));
+        if (StringUtils.isEmpty(content)) {
+            return Collections.emptyList();
+        }
+        return new ArrayList<String>(Arrays.asList(URL.decode(content)));
     }
 
     @Override
     protected void doSaveSubscriberData(SubscriberMetadataIdentifier 
subscriberMetadataIdentifier, String urlListStr) {
-
+        String key = getNodeKey(subscriberMetadataIdentifier);
+        if (!etcdClient.put(key, urlListStr)) {
+            logger.error("Failed to put " + subscriberMetadataIdentifier + " 
to etcd, value: " + urlListStr);
+        }
     }
 
     @Override
@@ -121,8 +137,8 @@ public class EtcdMetadataReport extends 
AbstractMetadataReport {
         }
     }
 
-    String getNodeKey(MetadataIdentifier identifier) {
-        return toRootDir() + 
identifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.PATH);
+    String getNodeKey(BaseMetadataIdentifier identifier) {
+        return toRootDir() + identifier.getUniqueKey(KeyTypeEnum.PATH);
     }
 
     String toRootDir() {
diff --git 
a/dubbo-metadata/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReport.java
 
b/dubbo-metadata/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReport.java
index bdbe759..6cd4bd2 100644
--- 
a/dubbo-metadata/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReport.java
+++ 
b/dubbo-metadata/dubbo-metadata-report-nacos/src/main/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReport.java
@@ -21,6 +21,8 @@ import org.apache.dubbo.common.URL;
 import org.apache.dubbo.common.logger.Logger;
 import org.apache.dubbo.common.logger.LoggerFactory;
 import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.metadata.report.identifier.BaseMetadataIdentifier;
+import org.apache.dubbo.metadata.report.identifier.KeyTypeEnum;
 import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier;
 import org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier;
 import 
org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier;
@@ -31,6 +33,9 @@ import com.alibaba.nacos.api.NacosFactory;
 import com.alibaba.nacos.api.config.ConfigService;
 import com.alibaba.nacos.api.exception.NacosException;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 import java.util.Properties;
 
@@ -127,37 +132,41 @@ public class NacosMetadataReport extends 
AbstractMetadataReport {
 
     @Override
     protected void doSaveMetadata(ServiceMetadataIdentifier 
serviceMetadataIdentifier, URL url) {
-        throw new UnsupportedOperationException("This extension does not 
support working as a remote metadata center.");
+        storeMetadata(serviceMetadataIdentifier, 
URL.encode(url.toFullString()));
     }
 
     @Override
     protected void doRemoveMetadata(ServiceMetadataIdentifier 
serviceMetadataIdentifier) {
-        throw new UnsupportedOperationException("This extension does not 
support working as a remote metadata center.");
+        deleteMetadata(serviceMetadataIdentifier);
     }
 
     @Override
     protected List<String> doGetExportedURLs(ServiceMetadataIdentifier 
metadataIdentifier) {
-        throw new UnsupportedOperationException("This extension does not 
support working as a remote metadata center.");
+        String content = getConfig(metadataIdentifier);
+        if (StringUtils.isEmpty(content)) {
+            return Collections.emptyList();
+        }
+        return new ArrayList<String>(Arrays.asList(URL.decode(content)));
     }
 
     @Override
     protected void doSaveSubscriberData(SubscriberMetadataIdentifier 
subscriberMetadataIdentifier, String urlListStr) {
-        throw new UnsupportedOperationException("This extension does not 
support working as a remote metadata center.");
+        storeMetadata(subscriberMetadataIdentifier, urlListStr);
     }
 
     @Override
     protected String doGetSubscribedURLs(SubscriberMetadataIdentifier 
subscriberMetadataIdentifier) {
-        throw new UnsupportedOperationException("This extension does not 
support working as a remote metadata center.");
+        return getConfig(subscriberMetadataIdentifier);
     }
 
     @Override
-    public String getServiceDefinition(MetadataIdentifier 
consumerMetadataIdentifier) {
-        throw new UnsupportedOperationException("This extension does not 
support working as a remote metadata center.");
+    public String getServiceDefinition(MetadataIdentifier metadataIdentifier) {
+        return getConfig(metadataIdentifier);
     }
 
-    private void storeMetadata(MetadataIdentifier identifier, String value) {
+    private void storeMetadata(BaseMetadataIdentifier identifier, String 
value) {
         try {
-            boolean publishResult = 
configService.publishConfig(identifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY),
 group, value);
+            boolean publishResult = 
configService.publishConfig(identifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), 
group, value);
             if (!publishResult) {
                 throw new RuntimeException("publish nacos metadata failed");
             }
@@ -166,4 +175,25 @@ public class NacosMetadataReport extends 
AbstractMetadataReport {
             throw new RpcException("Failed to put " + identifier + " to nacos 
" + value + ", cause: " + t.getMessage(), t);
         }
     }
+
+    private void deleteMetadata(BaseMetadataIdentifier identifier) {
+        try {
+            boolean publishResult = 
configService.removeConfig(identifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), 
group);
+            if (!publishResult) {
+                throw new RuntimeException("remove nacos metadata failed");
+            }
+        } catch (Throwable t) {
+            logger.error("Failed to remove " + identifier + " from nacos , 
cause: " + t.getMessage(), t);
+            throw new RpcException("Failed to remove " + identifier + " from 
nacos , cause: " + t.getMessage(), t);
+        }
+    }
+
+    private String getConfig(BaseMetadataIdentifier identifier) {
+        try {
+            return 
configService.getConfig(identifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), group, 
300);
+        } catch (Throwable t) {
+            logger.error("Failed to get " + identifier + " from nacos , cause: 
" + t.getMessage(), t);
+            throw new RpcException("Failed to get " + identifier + " from 
nacos , cause: " + t.getMessage(), t);
+        }
+    }
 }
diff --git 
a/dubbo-metadata/dubbo-metadata-report-nacos/src/test/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReportTest.java
 
b/dubbo-metadata/dubbo-metadata-report-nacos/src/test/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReportTest.java
index 666ec12..c441635 100644
--- 
a/dubbo-metadata/dubbo-metadata-report-nacos/src/test/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReportTest.java
+++ 
b/dubbo-metadata/dubbo-metadata-report-nacos/src/test/java/org/apache/dubbo/metadata/store/nacos/NacosMetadataReportTest.java
@@ -20,6 +20,7 @@ import org.apache.dubbo.common.URL;
 import org.apache.dubbo.common.utils.NetUtils;
 import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder;
 import org.apache.dubbo.metadata.definition.model.FullServiceDefinition;
+import org.apache.dubbo.metadata.report.identifier.KeyTypeEnum;
 import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier;
 
 import com.alibaba.nacos.api.config.ConfigService;
@@ -68,7 +69,7 @@ public class NacosMetadataReportTest {
         String application = "nacos-metdata-report-test";
         MetadataIdentifier providerIdentifier =
                 storeProvider(nacosMetadataReport, TEST_SERVICE, version, 
group, application);
-        String serverContent = 
configService.getConfig(providerIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY),
 NACOS_GROUP, 5000L);
+        String serverContent = 
configService.getConfig(providerIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY),
 NACOS_GROUP, 5000L);
         Assertions.assertNotNull(serverContent);
 
         Gson gson = new Gson();
@@ -83,7 +84,7 @@ public class NacosMetadataReportTest {
         String application = "nacos-metadata-report-consumer-test";
         MetadataIdentifier consumerIdentifier = 
storeConsumer(nacosMetadataReport, TEST_SERVICE, version, group, application);
 
-        String serverContent = 
configService.getConfig(consumerIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY),
 NACOS_GROUP, 5000L);
+        String serverContent = 
configService.getConfig(consumerIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY),
 NACOS_GROUP, 5000L);
         Assertions.assertNotNull(serverContent);
         Assertions.assertEquals(serverContent, 
"{\"paramConsumerTest\":\"nacosConsumer\"}");
     }
diff --git 
a/dubbo-metadata/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java
 
b/dubbo-metadata/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java
index c9b3bb4..c00be04 100644
--- 
a/dubbo-metadata/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java
+++ 
b/dubbo-metadata/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java
@@ -19,6 +19,9 @@ package org.apache.dubbo.metadata.store.redis;
 import org.apache.dubbo.common.URL;
 import org.apache.dubbo.common.logger.Logger;
 import org.apache.dubbo.common.logger.LoggerFactory;
+import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.metadata.report.identifier.BaseMetadataIdentifier;
+import org.apache.dubbo.metadata.report.identifier.KeyTypeEnum;
 import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier;
 import org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier;
 import 
org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier;
@@ -32,6 +35,9 @@ import redis.clients.jedis.JedisCluster;
 import redis.clients.jedis.JedisPool;
 import redis.clients.jedis.JedisPoolConfig;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -82,35 +88,39 @@ public class RedisMetadataReport extends 
AbstractMetadataReport {
 
     @Override
     protected void doSaveMetadata(ServiceMetadataIdentifier 
serviceMetadataIdentifier, URL url) {
-
+        this.storeMetadata(serviceMetadataIdentifier, 
URL.encode(url.toFullString()));
     }
 
     @Override
     protected void doRemoveMetadata(ServiceMetadataIdentifier 
serviceMetadataIdentifier) {
-
+        this.deleteMetadata(serviceMetadataIdentifier);
     }
 
     @Override
     protected List<String> doGetExportedURLs(ServiceMetadataIdentifier 
metadataIdentifier) {
-        return null;
+        String content = getMetadata(metadataIdentifier);
+        if (StringUtils.isEmpty(content)) {
+            return Collections.emptyList();
+        }
+        return new ArrayList<String>(Arrays.asList(URL.decode(content)));
     }
 
     @Override
     protected void doSaveSubscriberData(SubscriberMetadataIdentifier 
subscriberMetadataIdentifier, String urlListStr) {
-        throw new UnsupportedOperationException("This extension does not 
support working as a remote metadata center.");
+        this.storeMetadata(subscriberMetadataIdentifier, urlListStr);
     }
 
     @Override
     protected String doGetSubscribedURLs(SubscriberMetadataIdentifier 
subscriberMetadataIdentifier) {
-        throw new UnsupportedOperationException("This extension does not 
support working as a remote metadata center.");
+        return this.getMetadata(subscriberMetadataIdentifier);
     }
 
     @Override
-    public String getServiceDefinition(MetadataIdentifier 
consumerMetadataIdentifier) {
-        throw new UnsupportedOperationException("This extension does not 
support working as a remote metadata center.");
+    public String getServiceDefinition(MetadataIdentifier metadataIdentifier) {
+        return this.getMetadata(metadataIdentifier);
     }
 
-    private void storeMetadata(MetadataIdentifier metadataIdentifier, String 
v) {
+    private void storeMetadata(BaseMetadataIdentifier metadataIdentifier, 
String v) {
         if (pool != null) {
             storeMetadataStandalone(metadataIdentifier, v);
         } else {
@@ -118,7 +128,7 @@ public class RedisMetadataReport extends 
AbstractMetadataReport {
         }
     }
 
-    private void storeMetadataInCluster(MetadataIdentifier metadataIdentifier, 
String v) {
+    private void storeMetadataInCluster(BaseMetadataIdentifier 
metadataIdentifier, String v) {
         try (JedisCluster jedisCluster = new JedisCluster(jedisClusterNodes, 
timeout, timeout, 2, password, new GenericObjectPoolConfig())) {
             jedisCluster.set(metadataIdentifier.getIdentifierKey() + 
META_DATA_STORE_TAG, v);
         } catch (Throwable e) {
@@ -127,13 +137,65 @@ public class RedisMetadataReport extends 
AbstractMetadataReport {
         }
     }
 
-    private void storeMetadataStandalone(MetadataIdentifier 
metadataIdentifier, String v) {
+    private void storeMetadataStandalone(BaseMetadataIdentifier 
metadataIdentifier, String v) {
         try (Jedis jedis = pool.getResource()) {
-            
jedis.set(metadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY),
 v);
+            jedis.set(metadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), 
v);
         } catch (Throwable e) {
             logger.error("Failed to put " + metadataIdentifier + " to redis " 
+ v + ", cause: " + e.getMessage(), e);
             throw new RpcException("Failed to put " + metadataIdentifier + " 
to redis " + v + ", cause: " + e.getMessage(), e);
         }
     }
 
+    private void deleteMetadata(BaseMetadataIdentifier metadataIdentifier) {
+        if (pool != null) {
+            deleteMetadataStandalone(metadataIdentifier);
+        } else {
+            deleteMetadataInCluster(metadataIdentifier);
+        }
+    }
+
+    private void deleteMetadataInCluster(BaseMetadataIdentifier 
metadataIdentifier) {
+        try (JedisCluster jedisCluster = new JedisCluster(jedisClusterNodes, 
timeout, timeout, 2, password, new GenericObjectPoolConfig())) {
+            jedisCluster.del(metadataIdentifier.getIdentifierKey() + 
META_DATA_STORE_TAG);
+        } catch (Throwable e) {
+            logger.error("Failed to delete " + metadataIdentifier + " from 
redis cluster , cause: " + e.getMessage(), e);
+            throw new RpcException("Failed to delete " + metadataIdentifier + 
" from redis cluster , cause: " + e.getMessage(), e);
+        }
+    }
+
+    private void deleteMetadataStandalone(BaseMetadataIdentifier 
metadataIdentifier) {
+        try (Jedis jedis = pool.getResource()) {
+            jedis.del(metadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY));
+        } catch (Throwable e) {
+            logger.error("Failed to delete " + metadataIdentifier + " from 
redis , cause: " + e.getMessage(), e);
+            throw new RpcException("Failed to delete " + metadataIdentifier + 
" from redis , cause: " + e.getMessage(), e);
+        }
+    }
+
+    private String getMetadata(BaseMetadataIdentifier metadataIdentifier) {
+        if (pool != null) {
+            return getMetadataStandalone(metadataIdentifier);
+        } else {
+            return getMetadataInCluster(metadataIdentifier);
+        }
+    }
+
+    private String getMetadataInCluster(BaseMetadataIdentifier 
metadataIdentifier) {
+        try (JedisCluster jedisCluster = new JedisCluster(jedisClusterNodes, 
timeout, timeout, 2, password, new GenericObjectPoolConfig())) {
+            return jedisCluster.get(metadataIdentifier.getIdentifierKey() + 
META_DATA_STORE_TAG);
+        } catch (Throwable e) {
+            logger.error("Failed to get " + metadataIdentifier + " from redis 
cluster , cause: " + e.getMessage(), e);
+            throw new RpcException("Failed to get " + metadataIdentifier + " 
from redis cluster , cause: " + e.getMessage(), e);
+        }
+    }
+
+    private String getMetadataStandalone(BaseMetadataIdentifier 
metadataIdentifier) {
+        try (Jedis jedis = pool.getResource()) {
+            return 
jedis.get(metadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY));
+        } catch (Throwable e) {
+            logger.error("Failed to get " + metadataIdentifier + " from redis 
, cause: " + e.getMessage(), e);
+            throw new RpcException("Failed to get " + metadataIdentifier + " 
from redis , cause: " + e.getMessage(), e);
+        }
+    }
+
 }
diff --git 
a/dubbo-metadata/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java
 
b/dubbo-metadata/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java
index 88105e2..61dd376 100644
--- 
a/dubbo-metadata/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java
+++ 
b/dubbo-metadata/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java
@@ -20,6 +20,7 @@ import org.apache.dubbo.common.URL;
 import org.apache.dubbo.common.utils.NetUtils;
 import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder;
 import org.apache.dubbo.metadata.definition.model.FullServiceDefinition;
+import org.apache.dubbo.metadata.report.identifier.KeyTypeEnum;
 import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier;
 import org.apache.dubbo.rpc.RpcException;
 
@@ -94,7 +95,7 @@ public class RedisMetadataReportTest {
         Jedis jedis = null;
         try {
             jedis = redisMetadataReport.pool.getResource();
-            String keyTmp = 
providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY);
+            String keyTmp = 
providerMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY);
             String value = jedis.get(keyTmp);
             if (value == null) {
                 Thread.sleep(moreTime);
@@ -110,7 +111,7 @@ public class RedisMetadataReportTest {
             throw new RpcException("Failed to put to redis . cause: " + 
e.getMessage(), e);
         } finally {
             if (jedis != null) {
-                
jedis.del(providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY));
+                
jedis.del(providerMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY));
             }
             redisMetadataReport.pool.close();
         }
@@ -134,7 +135,7 @@ public class RedisMetadataReportTest {
         Jedis jedis = null;
         try {
             jedis = redisMetadataReport.pool.getResource();
-            String keyTmp = 
consumerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY);
+            String keyTmp = 
consumerMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY);
             String value = jedis.get(keyTmp);
             if (value == null) {
                 Thread.sleep(moreTime);
@@ -145,7 +146,7 @@ public class RedisMetadataReportTest {
             throw new RpcException("Failed to put to redis . cause: " + 
e.getMessage(), e);
         } finally {
             if (jedis != null) {
-                
jedis.del(consumerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY));
+                
jedis.del(consumerMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY));
             }
             redisMetadataReport.pool.close();
         }
diff --git 
a/dubbo-metadata/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport.java
 
b/dubbo-metadata/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport.java
index b370a62..9ca2e42 100644
--- 
a/dubbo-metadata/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport.java
+++ 
b/dubbo-metadata/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport.java
@@ -19,6 +19,9 @@ package org.apache.dubbo.metadata.store.zookeeper;
 import org.apache.dubbo.common.URL;
 import org.apache.dubbo.common.logger.Logger;
 import org.apache.dubbo.common.logger.LoggerFactory;
+import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.metadata.report.identifier.BaseMetadataIdentifier;
+import org.apache.dubbo.metadata.report.identifier.KeyTypeEnum;
 import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier;
 import org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier;
 import 
org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier;
@@ -28,6 +31,7 @@ import 
org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 
 import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
@@ -86,7 +90,11 @@ public class ZookeeperMetadataReport extends 
AbstractMetadataReport {
 
     @Override
     protected List<String> doGetExportedURLs(ServiceMetadataIdentifier 
metadataIdentifier) {
-        return new 
ArrayList<String>(Arrays.asList(URL.decode(zkClient.getContent(getNodePath(metadataIdentifier)))));
+        String content = zkClient.getContent(getNodePath(metadataIdentifier));
+        if (StringUtils.isEmpty(content)) {
+            return Collections.emptyList();
+        }
+        return new ArrayList<String>(Arrays.asList(URL.decode(content)));
     }
 
     @Override
@@ -108,17 +116,8 @@ public class ZookeeperMetadataReport extends 
AbstractMetadataReport {
         zkClient.create(getNodePath(metadataIdentifier), v, false);
     }
 
-    String getNodePath(MetadataIdentifier metadataIdentifier) {
-        return toRootDir() + 
metadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.PATH);
-    }
-
-    String getNodePath(ServiceMetadataIdentifier metadataIdentifier) {
-        return toRootDir() + 
metadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.PATH);
+    String getNodePath(BaseMetadataIdentifier metadataIdentifier) {
+        return toRootDir() + metadataIdentifier.getUniqueKey(KeyTypeEnum.PATH);
     }
 
-    String getNodePath(SubscriberMetadataIdentifier metadataIdentifier) {
-        return toRootDir() + 
metadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.PATH);
-    }
-
-
 }
diff --git 
a/dubbo-metadata/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java
 
b/dubbo-metadata/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java
index 55912f0..6b5d3b5 100644
--- 
a/dubbo-metadata/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java
+++ 
b/dubbo-metadata/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java
@@ -20,6 +20,7 @@ import org.apache.dubbo.common.URL;
 import org.apache.dubbo.common.utils.NetUtils;
 import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder;
 import org.apache.dubbo.metadata.definition.model.FullServiceDefinition;
+import org.apache.dubbo.metadata.report.identifier.KeyTypeEnum;
 import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier;
 import org.apache.dubbo.remoting.zookeeper.curator.CuratorZookeeperTransporter;
 
@@ -62,7 +63,7 @@ public class ZookeeperMetadataReportTest {
     }
 
     private void deletePath(MetadataIdentifier metadataIdentifier, 
ZookeeperMetadataReport zookeeperMetadataReport) {
-        String category = zookeeperMetadataReport.toRootDir() + 
metadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.PATH);
+        String category = zookeeperMetadataReport.toRootDir() + 
metadataIdentifier.getUniqueKey(KeyTypeEnum.PATH);
         zookeeperMetadataReport.zkClient.delete(category);
     }
 

Reply via email to