This is an automated email from the ASF dual-hosted git repository.
liuhongyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new cf0bbba7d6 [type:optimize] Optimize instance comparison logic in
EurekaInstanceRegisterRepository (#6154)
cf0bbba7d6 is described below
commit cf0bbba7d6e7937a48dd9d4745bfa742f4468658
Author: yqw570994511 <[email protected]>
AuthorDate: Sat Sep 13 15:12:16 2025 +0800
[type:optimize] Optimize instance comparison logic in
EurekaInstanceRegisterRepository (#6154)
Co-authored-by: yuqianwei <qq120405>
---
.../shenyu/registry/eureka/EurekaInstanceRegisterRepository.java | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git
a/shenyu-registry/shenyu-registry-eureka/src/main/java/org/apache/shenyu/registry/eureka/EurekaInstanceRegisterRepository.java
b/shenyu-registry/shenyu-registry-eureka/src/main/java/org/apache/shenyu/registry/eureka/EurekaInstanceRegisterRepository.java
index 4a9be294c9..857f3c5a2c 100644
---
a/shenyu-registry/shenyu-registry-eureka/src/main/java/org/apache/shenyu/registry/eureka/EurekaInstanceRegisterRepository.java
+++
b/shenyu-registry/shenyu-registry-eureka/src/main/java/org/apache/shenyu/registry/eureka/EurekaInstanceRegisterRepository.java
@@ -46,6 +46,7 @@ import org.slf4j.LoggerFactory;
import java.net.URI;
import java.util.Arrays;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -158,7 +159,7 @@ public class EurekaInstanceRegisterRepository implements
ShenyuInstanceRegisterR
try {
List<InstanceInfo> previousInstances =
instanceListMap.get(key);
List<InstanceInfo> currentInstances =
eurekaClient.getInstancesByVipAddressAndAppName(null, key, true);
- compareInstances(previousInstances, currentInstances,
listener);
+ compareInstances(new HashSet<>(previousInstances), new
HashSet<>(currentInstances), listener);
instanceListMap.put(key, currentInstances);
} catch (Exception e) {
LOGGER.error("eureka registry eurekaDiscoveryService watch
key: {} error", key, e);
@@ -188,7 +189,7 @@ public class EurekaInstanceRegisterRepository implements
ShenyuInstanceRegisterR
}
}
- private void compareInstances(final List<InstanceInfo> previousInstances,
final List<InstanceInfo> currentInstances, final ChangedEventListener listener)
{
+ private void compareInstances(final Set<InstanceInfo> previousInstances,
final Set<InstanceInfo> currentInstances, final ChangedEventListener listener) {
Set<InstanceInfo> addedInstances = currentInstances.stream()
.filter(item -> !previousInstances.contains(item))
.collect(Collectors.toSet());