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

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


The following commit(s) were added to refs/heads/3.2 by this push:
     new c283c41347 Only support rest convert when all servers are from spring 
cloud (#11888)
c283c41347 is described below

commit c283c4134794ed3d252855d38bde666c82d121c5
Author: Albumen Kevin <[email protected]>
AuthorDate: Thu Mar 23 17:51:05 2023 +0800

    Only support rest convert when all servers are from spring cloud (#11888)
---
 ...CloudServiceInstanceNotificationCustomizer.java | 36 +++++++++++++---------
 1 file changed, 21 insertions(+), 15 deletions(-)

diff --git 
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/SpringCloudServiceInstanceNotificationCustomizer.java
 
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/SpringCloudServiceInstanceNotificationCustomizer.java
index 444f08fb69..750eb6e6e9 100644
--- 
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/SpringCloudServiceInstanceNotificationCustomizer.java
+++ 
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/SpringCloudServiceInstanceNotificationCustomizer.java
@@ -28,24 +28,30 @@ import java.util.concurrent.ConcurrentHashMap;
 public class SpringCloudServiceInstanceNotificationCustomizer implements 
ServiceInstanceNotificationCustomizer {
     @Override
     public void customize(List<ServiceInstance> serviceInstance) {
+        if (serviceInstance.isEmpty()) {
+            return;
+        }
+
+        if (!serviceInstance.stream().allMatch(instance -> 
"SPRING_CLOUD".equals(instance.getMetadata("preserved.register.source")))) {
+            return;
+        }
+
         for (ServiceInstance instance : serviceInstance) {
-            if 
("SPRING_CLOUD".equals(instance.getMetadata("preserved.register.source"))) {
-                MetadataInfo.ServiceInfo serviceInfo = new 
MetadataInfo.ServiceInfo("*", "*", "*", "rest", instance.getPort(), "*", new 
HashMap<>());
-                String revision = "SPRING_CLOUD-" + instance.getServiceName() 
+ "-" + instance.getAddress() + "-" + instance.getPort();
-                MetadataInfo metadataInfo = new 
MetadataInfo(instance.getServiceName(), revision, new 
ConcurrentHashMap<>(Collections.singletonMap("*", serviceInfo))) {
-                    @Override
-                    public List<ServiceInfo> 
getMatchedServiceInfos(ProtocolServiceKey consumerProtocolServiceKey) {
-                        
getServices().putIfAbsent(consumerProtocolServiceKey.getServiceKeyString(),
-                            new 
MetadataInfo.ServiceInfo(consumerProtocolServiceKey.getInterfaceName(),
-                                consumerProtocolServiceKey.getGroup(), 
consumerProtocolServiceKey.getVersion(),
-                                consumerProtocolServiceKey.getProtocol(), 
instance.getPort(), consumerProtocolServiceKey.getInterfaceName(), new 
HashMap<>()));
-                        return 
super.getMatchedServiceInfos(consumerProtocolServiceKey);
-                    }
-                };
+            MetadataInfo.ServiceInfo serviceInfo = new 
MetadataInfo.ServiceInfo("*", "*", "*", "rest", instance.getPort(), "*", new 
HashMap<>());
+            String revision = "SPRING_CLOUD-" + instance.getServiceName() + 
"-" + instance.getAddress() + "-" + instance.getPort();
+            MetadataInfo metadataInfo = new 
MetadataInfo(instance.getServiceName(), revision, new 
ConcurrentHashMap<>(Collections.singletonMap("*", serviceInfo))) {
+                @Override
+                public List<ServiceInfo> 
getMatchedServiceInfos(ProtocolServiceKey consumerProtocolServiceKey) {
+                    
getServices().putIfAbsent(consumerProtocolServiceKey.getServiceKeyString(),
+                        new 
MetadataInfo.ServiceInfo(consumerProtocolServiceKey.getInterfaceName(),
+                            consumerProtocolServiceKey.getGroup(), 
consumerProtocolServiceKey.getVersion(),
+                            consumerProtocolServiceKey.getProtocol(), 
instance.getPort(), consumerProtocolServiceKey.getInterfaceName(), new 
HashMap<>()));
+                    return 
super.getMatchedServiceInfos(consumerProtocolServiceKey);
+                }
+            };
 
 
-                instance.setServiceMetadata(metadataInfo);
-            }
+            instance.setServiceMetadata(metadataInfo);
         }
     }
 }

Reply via email to