From 36a71ac8624e782962bd32eb1c0408ccadce7ff7 Mon Sep 17 00:00:00 2001 From: Fishtail <49390359+fuyuwei01@users.noreply.github.com> Date: Tue, 13 Aug 2024 20:53:09 +0800 Subject: [PATCH] fix: fix the lossless provider override in multiple registries scenario (#1380) Co-authored-by: Haotian Zhang Co-authored-by: andrew shan <45474304+andrewshan@users.noreply.github.com> --- CHANGELOG.md | 1 + .../adapter/transformer/NacosRegistrationTransformer.java | 5 +++++ .../transformer/PolarisRegistrationTransformer.java | 6 ++++-- .../enhancement/transformer/RegistrationTransformer.java | 3 +++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index daf067e55..c6a498136 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,3 +8,4 @@ - [feat: support lossless online and offline](https://github.com/Tencent/spring-cloud-tencent/pull/1377) - [feat: support lane router](https://github.com/Tencent/spring-cloud-tencent/pull/1378) - [feat: add lane router examples](https://github.com/Tencent/spring-cloud-tencent/pull/1379) +- [fix: fix the lossless provider override in multiple registries scenario](https://github.com/Tencent/spring-cloud-tencent/pull/1380) diff --git a/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-discovery-adapter-plugin/src/main/java/com/tencent/cloud/plugin/discovery/adapter/transformer/NacosRegistrationTransformer.java b/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-discovery-adapter-plugin/src/main/java/com/tencent/cloud/plugin/discovery/adapter/transformer/NacosRegistrationTransformer.java index c90d2b388..9d2f44cf6 100644 --- a/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-discovery-adapter-plugin/src/main/java/com/tencent/cloud/plugin/discovery/adapter/transformer/NacosRegistrationTransformer.java +++ b/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-discovery-adapter-plugin/src/main/java/com/tencent/cloud/plugin/discovery/adapter/transformer/NacosRegistrationTransformer.java @@ -28,6 +28,11 @@ import org.springframework.cloud.client.serviceregistry.Registration; public class NacosRegistrationTransformer implements RegistrationTransformer { + @Override + public String getRegistry() { + return "nacos"; + } + @Override public void transformCustom(DefaultInstance instance, Registration registration) { if (registration instanceof NacosRegistration) { diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/transformer/PolarisRegistrationTransformer.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/transformer/PolarisRegistrationTransformer.java index 8c4000a76..20df4f183 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/transformer/PolarisRegistrationTransformer.java +++ b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/transformer/PolarisRegistrationTransformer.java @@ -20,6 +20,8 @@ package com.tencent.cloud.rpc.enhancement.transformer; public class PolarisRegistrationTransformer implements RegistrationTransformer { - - + @Override + public String getRegistry() { + return "polaris"; + } } diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/transformer/RegistrationTransformer.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/transformer/RegistrationTransformer.java index c79fe3401..7996ebd78 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/transformer/RegistrationTransformer.java +++ b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/transformer/RegistrationTransformer.java @@ -32,6 +32,8 @@ import org.springframework.cloud.client.serviceregistry.Registration; */ public interface RegistrationTransformer { + String getRegistry(); + default Instance transform(Registration registration) { DefaultInstance instance = new DefaultInstance(); transformDefault(instance, registration); @@ -40,6 +42,7 @@ public interface RegistrationTransformer { } default void transformDefault(DefaultInstance instance, Registration registration) { + instance.setRegistry(getRegistry()); instance.setNamespace(MetadataContext.LOCAL_NAMESPACE); instance.setService(registration.getServiceId()); instance.setProtocol(registration.getScheme());