From ba462408e6c915231f48a08e071557b78bcc2805 Mon Sep 17 00:00:00 2001 From: Haotian Zhang Date: Wed, 17 Apr 2024 18:00:04 +0800 Subject: [PATCH] fix: fix the lossless provider override in multiple registries scenario (#1271) 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 971bd51cf..50a173eae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,3 +7,4 @@ - [feat: support lossless online and offline](https://github.com/Tencent/spring-cloud-tencent/pull/1268) - [feat: support lane router](https://github.com/Tencent/spring-cloud-tencent/pull/1269) - [feat: add lane router examples](https://github.com/Tencent/spring-cloud-tencent/pull/1270) +- [fix: fix the lossless provider override in multiple registries scenario](https://github.com/Tencent/spring-cloud-tencent/pull/1271) 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 553e829d4..5d0f3f6c4 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 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());