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

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


The following commit(s) were added to refs/heads/master by this push:
     new 9461f58  Nacos service discovery support service reversion and 
serviceName maping. (#7725)
9461f58 is described below

commit 9461f5842afa1a68d8ea9fb477a1c8f84c07897c
Author: 赵延 <[email protected]>
AuthorDate: Thu May 13 11:47:00 2021 +0800

    Nacos service discovery support service reversion and serviceName maping. 
(#7725)
    
    * nacos service discovery support service reversion and serviceName mapping.
    
    * set metadata null with initial value.
---
 .../metadata/store/nacos/NacosMetadataReport.java  | 26 ++++++++++++++++++++++
 .../listener/ServiceInstancesChangedListener.java  |  7 +++---
 2 files changed, 29 insertions(+), 4 deletions(-)

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 c59f3ba..1a507f8 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
@@ -19,6 +19,7 @@ package org.apache.dubbo.metadata.store.nacos;
 
 import org.apache.dubbo.common.URL;
 import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.metadata.MetadataInfo;
 import org.apache.dubbo.metadata.report.identifier.BaseMetadataIdentifier;
 import org.apache.dubbo.metadata.report.identifier.KeyTypeEnum;
 import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier;
@@ -29,11 +30,13 @@ import org.apache.dubbo.rpc.RpcException;
 
 import com.alibaba.nacos.api.NacosFactory;
 import com.alibaba.nacos.api.exception.NacosException;
+import com.google.gson.Gson;
 
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
+import java.util.Map;
 import java.util.Properties;
 
 import static com.alibaba.nacos.api.PropertyKeyConst.ACCESS_KEY;
@@ -66,6 +69,8 @@ public class NacosMetadataReport extends 
AbstractMetadataReport {
 
     private NacosConfigServiceWrapper configService;
 
+    private Gson gson = new Gson();
+
     /**
      * The group used to store metadata in Nacos
      */
@@ -151,6 +156,26 @@ public class NacosMetadataReport extends 
AbstractMetadataReport {
     }
 
     @Override
+    public void publishAppMetadata(SubscriberMetadataIdentifier identifier, 
MetadataInfo metadataInfo) {
+        String content = gson.toJson(metadataInfo);
+        try {
+            configService.publishConfig(identifier.getApplication(), 
identifier.getRevision(), content);
+        } catch (NacosException e) {
+            throw new IllegalStateException(e.getMessage(), e);
+        }
+    }
+
+    @Override
+    public MetadataInfo getAppMetadata(SubscriberMetadataIdentifier 
identifier, Map<String, String> instanceMetadata) {
+        try {
+            String content = 
configService.getConfig(identifier.getApplication(), identifier.getRevision(), 
3000L);
+            return gson.fromJson(content, MetadataInfo.class);
+        } catch (NacosException e) {
+            throw new IllegalStateException(e.getMessage(), e);
+        }
+    }
+
+    @Override
     protected void doStoreProviderMetadata(MetadataIdentifier 
providerMetadataIdentifier, String serviceDefinitions) {
         this.storeMetadata(providerMetadataIdentifier, serviceDefinitions);
     }
@@ -226,4 +251,5 @@ public class NacosMetadataReport extends 
AbstractMetadataReport {
             throw new RpcException("Failed to get " + identifier + " from 
nacos , cause: " + t.getMessage(), t);
         }
     }
+
 }
diff --git 
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/event/listener/ServiceInstancesChangedListener.java
 
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/event/listener/ServiceInstancesChangedListener.java
index 58f3334..25f96a4 100644
--- 
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/event/listener/ServiceInstancesChangedListener.java
+++ 
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/event/listener/ServiceInstancesChangedListener.java
@@ -168,10 +168,10 @@ public class ServiceInstancesChangedListener implements 
ConditionalEventListener
         String metadataType = 
ServiceInstanceMetadataUtils.getMetadataStorageType(instance);
         // FIXME, check "REGISTRY_CLUSTER_KEY" must be set by every registry 
implementation.
         instance.getExtendParams().putIfAbsent(REGISTRY_CLUSTER_KEY, 
RegistryClusterIdentifier.getExtension(url).consumerKey(url));
-        MetadataInfo metadataInfo;
+        MetadataInfo metadataInfo = null;
         try {
             if (logger.isDebugEnabled()) {
-                logger.info("Instance " + instance.getAddress() + " is using 
metadata type " + metadataType);
+                logger.debug("Instance " + instance.getAddress() + " is using 
metadata type " + metadataType);
             }
             if (REMOTE_METADATA_STORAGE_TYPE.equals(metadataType)) {
                 RemoteMetadataServiceImpl remoteMetadataService = 
MetadataUtils.getRemoteMetadataService();
@@ -181,11 +181,10 @@ public class ServiceInstancesChangedListener implements 
ConditionalEventListener
                 metadataInfo = 
metadataServiceProxy.getMetadataInfo(ServiceInstanceMetadataUtils.getExportedServicesRevision(instance));
             }
             if (logger.isDebugEnabled()) {
-                logger.info("Metadata " + metadataInfo.toString());
+                logger.debug("Metadata " + metadataInfo.toString());
             }
         } catch (Exception e) {
             logger.error("Failed to load service metadata, metadata type is " 
+ metadataType, e);
-            metadataInfo = null;
             // TODO, load metadata backup. Stop getting metadata after x times 
of failure for one revision?
         }
         return metadataInfo;

Reply via email to