diff --git a/CHANGELOG.md b/CHANGELOG.md index 905b7734a..d646087e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,4 +9,5 @@ - [feature: improve circuit breaker usage.](https://github.com/Tencent/spring-cloud-tencent/pull/916) - [fix:fix nacos and consul registration.](https://github.com/Tencent/spring-cloud-tencent/pull/919) - [Documentation content changes: add circuitbreaker readme.](https://github.com/Tencent/spring-cloud-tencent/pull/929) -- [fix: fix PolarisRouterServiceInstanceListSupplier npe with reactive feign.](https://github.com/Tencent/spring-cloud-tencent/pull/925) \ No newline at end of file +- [fix: fix PolarisRouterServiceInstanceListSupplier npe with reactive feign.](https://github.com/Tencent/spring-cloud-tencent/pull/925) +- [fix: adapt for nacos instance.](https://github.com/Tencent/spring-cloud-tencent/pull/933) \ No newline at end of file diff --git a/pom.xml b/pom.xml index 10c7efab7..df7a07d2a 100644 --- a/pom.xml +++ b/pom.xml @@ -88,7 +88,7 @@ - 1.11.0-2020.0.6-SNAPSHOT + 1.10.3-2020.0.6 5.3.25 diff --git a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/test/java/com/tencent/cloud/polaris/circuitbreaker/PolarisCircuitBreakerGatewayIntegrationTest.java b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/test/java/com/tencent/cloud/polaris/circuitbreaker/PolarisCircuitBreakerGatewayIntegrationTest.java index 22513c613..45c8d20fd 100644 --- a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/test/java/com/tencent/cloud/polaris/circuitbreaker/PolarisCircuitBreakerGatewayIntegrationTest.java +++ b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/test/java/com/tencent/cloud/polaris/circuitbreaker/PolarisCircuitBreakerGatewayIntegrationTest.java @@ -81,7 +81,7 @@ import static org.assertj.core.api.Assertions.assertThat; ) @AutoConfigureWireMock(port = 0) @ActiveProfiles("test-gateway") -@AutoConfigureWebTestClient(timeout = "10000") +@AutoConfigureWebTestClient(timeout = "1000000") public class PolarisCircuitBreakerGatewayIntegrationTest { private static final String TEST_SERVICE_NAME = "test-service-callee"; diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/endpoint/PolarisDiscoveryEndpointTest.java b/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/endpoint/PolarisDiscoveryEndpointTest.java index 14152df62..d8ff2b813 100644 --- a/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/endpoint/PolarisDiscoveryEndpointTest.java +++ b/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/endpoint/PolarisDiscoveryEndpointTest.java @@ -16,6 +16,7 @@ */ package com.tencent.cloud.polaris.endpoint; +import java.util.Collections; import java.util.Map; import com.tencent.cloud.polaris.PolarisDiscoveryProperties; @@ -38,6 +39,8 @@ import static com.tencent.polaris.test.common.Consts.NAMESPACE_TEST; import static com.tencent.polaris.test.common.Consts.PORT; import static com.tencent.polaris.test.common.Consts.SERVICE_PROVIDER; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; /** * Test for polaris discovery endpoint. @@ -79,12 +82,17 @@ public class PolarisDiscoveryEndpointTest { .getBean(PolarisDiscoveryProperties.class); DiscoveryClient discoveryClient = context .getBean(PolarisDiscoveryClient.class); + PolarisDiscoveryHandler polarisDiscoveryHandler = context.getBean(PolarisDiscoveryHandler.class); PolarisDiscoveryEndpoint polarisDiscoveryEndpoint = new PolarisDiscoveryEndpoint(polarisDiscoveryProperties, discoveryClient, polarisDiscoveryHandler); - Map mapInfo = polarisDiscoveryEndpoint.polarisDiscovery("java_provider_test"); - assertThat(polarisDiscoveryProperties).isEqualTo(mapInfo.get("PolarisDiscoveryProperties")); + + DiscoveryClient discoveryClient1 = mock(DiscoveryClient.class); + doReturn(Collections.singletonList("xx")).when(discoveryClient1).getServices(); + PolarisDiscoveryEndpoint polarisDiscoveryEndpoint1 = new PolarisDiscoveryEndpoint(polarisDiscoveryProperties, discoveryClient1, polarisDiscoveryHandler); + Map mapInfo2 = polarisDiscoveryEndpoint1.polarisDiscovery(null); + assertThat(polarisDiscoveryProperties).isEqualTo(mapInfo2.get("PolarisDiscoveryProperties")); }); } diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/registry/PolarisRegistrationTest.java b/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/registry/PolarisRegistrationTest.java index ff8de26a1..ebcc5ea4b 100644 --- a/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/registry/PolarisRegistrationTest.java +++ b/spring-cloud-starter-tencent-polaris-discovery/src/test/java/com/tencent/cloud/polaris/registry/PolarisRegistrationTest.java @@ -76,9 +76,17 @@ public class PolarisRegistrationTest { doReturn(true).when(consulContextProperties).isRegister(); // mock NacosContextProperties - nacosContextProperties = mock(NacosContextProperties.class); - doReturn(true).when(nacosContextProperties).isEnabled(); - doReturn(true).when(nacosContextProperties).isRegisterEnabled(); + nacosContextProperties = new NacosContextProperties(); + nacosContextProperties.setEnabled(true); + nacosContextProperties.setRegisterEnabled(true); + nacosContextProperties.setContextPath("/"); + nacosContextProperties.setClusterName("cluster"); + nacosContextProperties.setGroup(""); + nacosContextProperties.setDiscoveryEnabled(true); + nacosContextProperties.setPassword(""); + nacosContextProperties.setUsername(""); + nacosContextProperties.setServerAddr(""); + nacosContextProperties.toString(); // mock SDKContext APIConfig apiConfig = mock(APIConfig.class); @@ -162,7 +170,7 @@ public class PolarisRegistrationTest { Map metadata = polarisRegistration1.getMetadata(); assertThat(metadata).isNotNull(); assertThat(metadata).isNotEmpty(); - assertThat(metadata.size()).isEqualTo(3); + assertThat(metadata.size()).isEqualTo(4); assertThat(metadata.get("key1")).isEqualTo("value1"); } diff --git a/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/PolarisRouterServiceInstanceListSupplier.java b/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/PolarisRouterServiceInstanceListSupplier.java index 2e8095430..e91490b04 100644 --- a/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/PolarisRouterServiceInstanceListSupplier.java +++ b/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/PolarisRouterServiceInstanceListSupplier.java @@ -33,6 +33,7 @@ import com.tencent.cloud.common.metadata.MetadataContextHolder; import com.tencent.cloud.common.pojo.PolarisServiceInstance; import com.tencent.cloud.common.util.JacksonUtils; import com.tencent.cloud.polaris.router.resttemplate.PolarisLoadBalancerRequest; +import com.tencent.cloud.polaris.router.spi.InstanceTransformer; import com.tencent.cloud.polaris.router.spi.RouterRequestInterceptor; import com.tencent.cloud.polaris.router.spi.RouterResponseInterceptor; import com.tencent.polaris.api.exception.ErrorCode; @@ -73,14 +74,16 @@ public class PolarisRouterServiceInstanceListSupplier extends DelegatingServiceI private final RouterAPI routerAPI; private final List requestInterceptors; private final List responseInterceptors; + private final InstanceTransformer instanceTransformer; public PolarisRouterServiceInstanceListSupplier(ServiceInstanceListSupplier delegate, RouterAPI routerAPI, List requestInterceptors, - List responseInterceptors) { + List responseInterceptors, InstanceTransformer instanceTransformer) { super(delegate); this.routerAPI = routerAPI; this.requestInterceptors = requestInterceptors; this.responseInterceptors = responseInterceptors; + this.instanceTransformer = instanceTransformer; } @Override @@ -143,7 +146,7 @@ public class PolarisRouterServiceInstanceListSupplier extends DelegatingServiceI } Flux> doRouter(Flux> allServers, PolarisRouterContext routerContext) { - ServiceInstances serviceInstances = RouterUtils.transferServersToServiceInstances(allServers); + ServiceInstances serviceInstances = RouterUtils.transferServersToServiceInstances(allServers, instanceTransformer); List filteredInstances = new ArrayList<>(); if (serviceInstances.getInstances().size() > 0) { diff --git a/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/RouterUtils.java b/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/RouterUtils.java index 334ffd425..e2947a317 100644 --- a/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/RouterUtils.java +++ b/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/RouterUtils.java @@ -25,8 +25,7 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; import com.tencent.cloud.common.metadata.MetadataContext; -import com.tencent.cloud.common.pojo.PolarisServiceInstance; -import com.tencent.polaris.api.pojo.DefaultInstance; +import com.tencent.cloud.polaris.router.spi.InstanceTransformer; import com.tencent.polaris.api.pojo.DefaultServiceInstances; import com.tencent.polaris.api.pojo.Instance; import com.tencent.polaris.api.pojo.ServiceInstances; @@ -57,14 +56,14 @@ public final class RouterUtils { * @param servers servers * @return ServiceInstances */ - public static ServiceInstances transferServersToServiceInstances(Flux> servers) { + public static ServiceInstances transferServersToServiceInstances(Flux> servers, InstanceTransformer instanceTransformer) { CountDownLatch latch = new CountDownLatch(1); AtomicReference> instancesRef = new AtomicReference<>(); servers.subscribe(serviceInstances -> { instancesRef.set(serviceInstances .stream() - .map(RouterUtils::transferServerToServiceInstance) + .map(instanceTransformer::transform) .collect(Collectors.toList())); latch.countDown(); @@ -87,31 +86,4 @@ public final class RouterUtils { return new DefaultServiceInstances(serviceKey, instances); } - - /** - * transfer ServiceInstance to DefaultInstance. - * - * @param serviceInstance serviceInstance - * @return defaultInstance - */ - public static DefaultInstance transferServerToServiceInstance(ServiceInstance serviceInstance) { - DefaultInstance instance = new DefaultInstance(); - instance.setNamespace(MetadataContext.LOCAL_NAMESPACE); - instance.setService(serviceInstance.getServiceId()); - instance.setProtocol(serviceInstance.getScheme()); - instance.setId(serviceInstance.getInstanceId()); - instance.setHost(serviceInstance.getHost()); - instance.setPort(serviceInstance.getPort()); - instance.setMetadata(serviceInstance.getMetadata()); - - if (serviceInstance instanceof PolarisServiceInstance) { - PolarisServiceInstance polarisServiceInstance = (PolarisServiceInstance) serviceInstance; - instance.setRegion(polarisServiceInstance.getPolarisInstance().getRegion()); - instance.setZone(polarisServiceInstance.getPolarisInstance().getZone()); - instance.setCampus(polarisServiceInstance.getPolarisInstance().getCampus()); - instance.setWeight(polarisServiceInstance.getPolarisInstance().getWeight()); - } - - return instance; - } } diff --git a/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/config/LoadBalancerConfiguration.java b/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/config/LoadBalancerConfiguration.java index 1ed979c03..2fe52773b 100644 --- a/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/config/LoadBalancerConfiguration.java +++ b/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/config/LoadBalancerConfiguration.java @@ -20,12 +20,17 @@ package com.tencent.cloud.polaris.router.config; import java.util.List; +import com.tencent.cloud.common.pojo.PolarisServiceInstance; import com.tencent.cloud.polaris.router.PolarisRouterServiceInstanceListSupplier; +import com.tencent.cloud.polaris.router.spi.InstanceTransformer; import com.tencent.cloud.polaris.router.spi.RouterRequestInterceptor; import com.tencent.cloud.polaris.router.spi.RouterResponseInterceptor; +import com.tencent.cloud.polaris.router.transformer.PolarisInstanceTransformer; import com.tencent.polaris.router.api.core.RouterAPI; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.cloud.client.ConditionalOnBlockingDiscoveryEnabled; import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled; import org.springframework.cloud.client.ConditionalOnReactiveDiscoveryEnabled; @@ -52,6 +57,13 @@ public class LoadBalancerConfiguration { */ private static final int REACTIVE_SERVICE_INSTANCE_SUPPLIER_ORDER = 193827465; + @Bean + @ConditionalOnMissingBean + @ConditionalOnClass(PolarisServiceInstance.class) + public InstanceTransformer instanceTransformer() { + return new PolarisInstanceTransformer(); + } + @Configuration(proxyBeanMethods = false) @ConditionalOnReactiveDiscoveryEnabled @Order(REACTIVE_SERVICE_INSTANCE_SUPPLIER_ORDER) @@ -62,12 +74,13 @@ public class LoadBalancerConfiguration { public ServiceInstanceListSupplier polarisRouterDiscoveryClientServiceInstanceListSupplier( ConfigurableApplicationContext context, RouterAPI routerAPI, List requestInterceptors, - List responseInterceptors) { + List responseInterceptors, InstanceTransformer instanceTransformer) { return new PolarisRouterServiceInstanceListSupplier( ServiceInstanceListSupplier.builder().withDiscoveryClient().build(context), routerAPI, requestInterceptors, - responseInterceptors); + responseInterceptors, + instanceTransformer); } } @@ -82,12 +95,13 @@ public class LoadBalancerConfiguration { public ServiceInstanceListSupplier polarisRouterDiscoveryClientServiceInstanceListSupplier( ConfigurableApplicationContext context, RouterAPI routerAPI, List requestInterceptors, - List responseInterceptors) { + List responseInterceptors, InstanceTransformer instanceTransformer) { return new PolarisRouterServiceInstanceListSupplier( ServiceInstanceListSupplier.builder().withBlockingDiscoveryClient().build(context), routerAPI, requestInterceptors, - responseInterceptors); + responseInterceptors, + instanceTransformer); } } } diff --git a/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/spi/InstanceTransformer.java b/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/spi/InstanceTransformer.java new file mode 100644 index 000000000..f5684299e --- /dev/null +++ b/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/spi/InstanceTransformer.java @@ -0,0 +1,53 @@ +/* + * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + */ + +package com.tencent.cloud.polaris.router.spi; + +import com.tencent.cloud.common.metadata.MetadataContext; +import com.tencent.polaris.api.pojo.DefaultInstance; +import com.tencent.polaris.api.pojo.Instance; + +import org.springframework.cloud.client.ServiceInstance; + +/** + * InstanceTransformer. + * + * @author sean yu + */ +public interface InstanceTransformer { + + default Instance transform(ServiceInstance serviceInstance) { + DefaultInstance instance = new DefaultInstance(); + transformDefault(instance, serviceInstance); + transformCustom(instance, serviceInstance); + return instance; + } + + default void transformDefault(DefaultInstance instance, ServiceInstance serviceInstance) { + instance.setNamespace(MetadataContext.LOCAL_NAMESPACE); + instance.setService(serviceInstance.getServiceId()); + instance.setProtocol(serviceInstance.getScheme()); + instance.setId(serviceInstance.getInstanceId()); + instance.setHost(serviceInstance.getHost()); + instance.setPort(serviceInstance.getPort()); + instance.setMetadata(serviceInstance.getMetadata()); + } + + void transformCustom(DefaultInstance instance, ServiceInstance serviceInstance); + +} diff --git a/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/transformer/PolarisInstanceTransformer.java b/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/transformer/PolarisInstanceTransformer.java new file mode 100644 index 000000000..183090362 --- /dev/null +++ b/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/transformer/PolarisInstanceTransformer.java @@ -0,0 +1,45 @@ +/* + * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + */ + +package com.tencent.cloud.polaris.router.transformer; + +import com.tencent.cloud.common.pojo.PolarisServiceInstance; +import com.tencent.cloud.polaris.router.spi.InstanceTransformer; +import com.tencent.polaris.api.pojo.DefaultInstance; + +import org.springframework.cloud.client.ServiceInstance; + +/** + * PolarisInstanceTransformer. + * + * @author sean yu + */ +public class PolarisInstanceTransformer implements InstanceTransformer { + + @Override + public void transformCustom(DefaultInstance instance, ServiceInstance serviceInstance) { + if (serviceInstance instanceof PolarisServiceInstance) { + PolarisServiceInstance polarisServiceInstance = (PolarisServiceInstance) serviceInstance; + instance.setRegion(polarisServiceInstance.getPolarisInstance().getRegion()); + instance.setZone(polarisServiceInstance.getPolarisInstance().getZone()); + instance.setCampus(polarisServiceInstance.getPolarisInstance().getCampus()); + instance.setWeight(polarisServiceInstance.getPolarisInstance().getWeight()); + } + } + +} diff --git a/spring-cloud-starter-tencent-polaris-router/src/test/java/com/tencent/cloud/polaris/router/PolarisRouterServiceInstanceListSupplierTest.java b/spring-cloud-starter-tencent-polaris-router/src/test/java/com/tencent/cloud/polaris/router/PolarisRouterServiceInstanceListSupplierTest.java index 84d2a738c..6ac5238a2 100644 --- a/spring-cloud-starter-tencent-polaris-router/src/test/java/com/tencent/cloud/polaris/router/PolarisRouterServiceInstanceListSupplierTest.java +++ b/spring-cloud-starter-tencent-polaris-router/src/test/java/com/tencent/cloud/polaris/router/PolarisRouterServiceInstanceListSupplierTest.java @@ -41,6 +41,7 @@ import com.tencent.cloud.polaris.router.interceptor.RuleBasedRouterRequestInterc import com.tencent.cloud.polaris.router.resttemplate.PolarisLoadBalancerRequest; import com.tencent.cloud.polaris.router.spi.RouterRequestInterceptor; import com.tencent.cloud.polaris.router.spi.RouterResponseInterceptor; +import com.tencent.cloud.polaris.router.transformer.PolarisInstanceTransformer; import com.tencent.polaris.api.exception.PolarisException; import com.tencent.polaris.api.pojo.DefaultInstance; import com.tencent.polaris.api.pojo.DefaultServiceInstances; @@ -120,7 +121,7 @@ public class PolarisRouterServiceInstanceListSupplierTest { setTransitiveMetadata(); PolarisRouterServiceInstanceListSupplier polarisSupplier = new PolarisRouterServiceInstanceListSupplier( - delegate, routerAPI, requestInterceptors, null); + delegate, routerAPI, requestInterceptors, null, new PolarisInstanceTransformer()); ServiceInstances serviceInstances = assembleServiceInstances(); PolarisRouterContext routerContext = assembleRouterContext(); @@ -157,7 +158,7 @@ public class PolarisRouterServiceInstanceListSupplierTest { setTransitiveMetadata(); PolarisRouterServiceInstanceListSupplier polarisSupplier = new PolarisRouterServiceInstanceListSupplier( - delegate, routerAPI, requestInterceptors, null); + delegate, routerAPI, requestInterceptors, null, new PolarisInstanceTransformer()); ServiceInstances serviceInstances = assembleServiceInstances(); PolarisRouterContext routerContext = assembleRouterContext(); @@ -195,7 +196,7 @@ public class PolarisRouterServiceInstanceListSupplierTest { setTransitiveMetadata(); PolarisRouterServiceInstanceListSupplier polarisSupplier = new PolarisRouterServiceInstanceListSupplier( - delegate, routerAPI, requestInterceptors, null); + delegate, routerAPI, requestInterceptors, null, new PolarisInstanceTransformer()); ServiceInstances serviceInstances = assembleServiceInstances(); PolarisRouterContext routerContext = assembleRouterContext(); @@ -222,7 +223,7 @@ public class PolarisRouterServiceInstanceListSupplierTest { setTransitiveMetadata(); PolarisRouterServiceInstanceListSupplier polarisSupplier = new PolarisRouterServiceInstanceListSupplier( - delegate, routerAPI, requestInterceptors, Collections.singletonList(new TestRouterResponseInterceptor())); + delegate, routerAPI, requestInterceptors, Collections.singletonList(new TestRouterResponseInterceptor()), new PolarisInstanceTransformer()); ProcessRoutersResponse assembleResponse = assembleProcessRoutersResponse(); when(routerAPI.processRouters(any())).thenReturn(assembleResponse); @@ -237,7 +238,7 @@ public class PolarisRouterServiceInstanceListSupplierTest { @Test public void buildRouterContext() { PolarisRouterServiceInstanceListSupplier polarisSupplier = new PolarisRouterServiceInstanceListSupplier( - delegate, routerAPI, requestInterceptors, null); + delegate, routerAPI, requestInterceptors, null, new PolarisInstanceTransformer()); HttpHeaders headers = new HttpHeaders(); PolarisRouterContext context = polarisSupplier.buildRouterContext(headers); @@ -259,7 +260,7 @@ public class PolarisRouterServiceInstanceListSupplierTest { @Test public void testGet01() { PolarisRouterServiceInstanceListSupplier polarisSupplier = new PolarisRouterServiceInstanceListSupplier( - delegate, routerAPI, requestInterceptors, null); + delegate, routerAPI, requestInterceptors, null, new PolarisInstanceTransformer()); assertThatThrownBy(() -> polarisSupplier.get()).isInstanceOf(PolarisException.class); } @@ -270,7 +271,7 @@ public class PolarisRouterServiceInstanceListSupplierTest { .thenReturn(testCallerService); PolarisRouterServiceInstanceListSupplier polarisSupplier = new PolarisRouterServiceInstanceListSupplier( - delegate, routerAPI, requestInterceptors, null); + delegate, routerAPI, requestInterceptors, null, new PolarisInstanceTransformer()); MockServerHttpRequest httpRequest = MockServerHttpRequest.get("/" + testCalleeService + "/users") .header("k1", "v1") @@ -294,7 +295,7 @@ public class PolarisRouterServiceInstanceListSupplierTest { .thenReturn(new ProcessRoutersResponse(new DefaultServiceInstances(null, new ArrayList<>()))); PolarisRouterServiceInstanceListSupplier polarisSupplier = new PolarisRouterServiceInstanceListSupplier( - delegate, routerAPI, requestInterceptors, null); + delegate, routerAPI, requestInterceptors, null, new PolarisInstanceTransformer()); MockServerHttpRequest httpRequest = MockServerHttpRequest.get("/" + testCalleeService + "/users") .header("k1", "v1") diff --git a/spring-cloud-starter-tencent-polaris-router/src/test/java/com/tencent/cloud/polaris/router/RouterUtilsTest.java b/spring-cloud-starter-tencent-polaris-router/src/test/java/com/tencent/cloud/polaris/router/RouterUtilsTest.java index 42fe721fa..724c401ee 100644 --- a/spring-cloud-starter-tencent-polaris-router/src/test/java/com/tencent/cloud/polaris/router/RouterUtilsTest.java +++ b/spring-cloud-starter-tencent-polaris-router/src/test/java/com/tencent/cloud/polaris/router/RouterUtilsTest.java @@ -24,6 +24,7 @@ import com.tencent.cloud.common.metadata.MetadataContext; import com.tencent.cloud.common.metadata.MetadataContextHolder; import com.tencent.cloud.common.pojo.PolarisServiceInstance; import com.tencent.cloud.common.util.ApplicationContextAwareUtils; +import com.tencent.cloud.polaris.router.transformer.PolarisInstanceTransformer; import com.tencent.polaris.api.pojo.DefaultInstance; import com.tencent.polaris.api.pojo.Instance; import com.tencent.polaris.api.pojo.ServiceInstances; @@ -52,7 +53,7 @@ public class RouterUtilsTest { @Test public void testTransferEmptyInstances() { - ServiceInstances serviceInstances = RouterUtils.transferServersToServiceInstances(Flux.empty()); + ServiceInstances serviceInstances = RouterUtils.transferServersToServiceInstances(Flux.empty(), new PolarisInstanceTransformer()); assertThat(serviceInstances.getInstances()).isNotNull(); assertThat(serviceInstances.getInstances()).isEmpty(); } @@ -82,7 +83,7 @@ public class RouterUtilsTest { instances.add(new PolarisServiceInstance(instance)); } - ServiceInstances serviceInstances = RouterUtils.transferServersToServiceInstances(Flux.just(instances)); + ServiceInstances serviceInstances = RouterUtils.transferServersToServiceInstances(Flux.just(instances), new PolarisInstanceTransformer()); assertThat(serviceInstances.getInstances()).isNotNull(); assertThat(serviceInstances.getInstances().size()).isEqualTo(instanceSize); diff --git a/spring-cloud-starter-tencent-polaris-router/src/test/java/com/tencent/cloud/polaris/router/config/LoadBalancerConfigurationTest.java b/spring-cloud-starter-tencent-polaris-router/src/test/java/com/tencent/cloud/polaris/router/config/LoadBalancerConfigurationTest.java index c773bc7c7..3f35570c8 100644 --- a/spring-cloud-starter-tencent-polaris-router/src/test/java/com/tencent/cloud/polaris/router/config/LoadBalancerConfigurationTest.java +++ b/spring-cloud-starter-tencent-polaris-router/src/test/java/com/tencent/cloud/polaris/router/config/LoadBalancerConfigurationTest.java @@ -20,6 +20,7 @@ package com.tencent.cloud.polaris.router.config; import com.tencent.cloud.polaris.context.config.PolarisContextAutoConfiguration; import com.tencent.cloud.polaris.router.PolarisRouterServiceInstanceListSupplier; +import com.tencent.cloud.polaris.router.transformer.PolarisInstanceTransformer; import com.tencent.polaris.router.api.core.RouterAPI; import org.junit.jupiter.api.Test; @@ -59,6 +60,7 @@ public class LoadBalancerConfigurationTest { PolarisContextAutoConfiguration.class)) .withBean(SimpleReactiveDiscoveryProperties.class) .withBean(SimpleReactiveDiscoveryClient.class) + .withBean(PolarisInstanceTransformer.class) .run(context -> { assertThat(context).hasSingleBean(LoadBalancerConfiguration.PolarisReactiveSupportConfiguration.class); assertThat(context).hasSingleBean(RouterAPI.class); @@ -75,6 +77,7 @@ public class LoadBalancerConfigurationTest { )) .withBean(SimpleDiscoveryProperties.class) .withBean(SimpleDiscoveryClient.class) + .withBean(PolarisInstanceTransformer.class) .run(context -> { assertThat(context).hasSingleBean(LoadBalancerConfiguration.PolarisBlockingSupportConfiguration.class); assertThat(context).hasSingleBean(DiscoveryClient.class); diff --git a/spring-cloud-starter-tencent-polaris-router/src/test/java/com/tencent/cloud/polaris/router/transformer/PolarisInstanceTransformerTest.java b/spring-cloud-starter-tencent-polaris-router/src/test/java/com/tencent/cloud/polaris/router/transformer/PolarisInstanceTransformerTest.java new file mode 100644 index 000000000..b723d46be --- /dev/null +++ b/spring-cloud-starter-tencent-polaris-router/src/test/java/com/tencent/cloud/polaris/router/transformer/PolarisInstanceTransformerTest.java @@ -0,0 +1,60 @@ +/* + * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + */ + +package com.tencent.cloud.polaris.router.transformer; + +import com.tencent.cloud.common.pojo.PolarisServiceInstance; +import com.tencent.cloud.common.util.ApplicationContextAwareUtils; +import com.tencent.polaris.api.pojo.DefaultInstance; +import com.tencent.polaris.api.pojo.Instance; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.mockito.MockedStatic; +import org.mockito.Mockito; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * PolarisInstanceTransformerTest. + * + * @author sean yu + */ +public class PolarisInstanceTransformerTest { + + private static MockedStatic mockedApplicationContextAwareUtils; + + @BeforeAll + public static void beforeAll() { + mockedApplicationContextAwareUtils = Mockito.mockStatic(ApplicationContextAwareUtils.class); + mockedApplicationContextAwareUtils.when(() -> ApplicationContextAwareUtils.getProperties("spring.cloud.polaris.namespace")) + .thenReturn("default"); + mockedApplicationContextAwareUtils.when(() -> ApplicationContextAwareUtils.getProperties("spring.cloud.polaris.service")) + .thenReturn("test"); + } + + + @Test + public void test() { + PolarisInstanceTransformer polarisInstanceTransformer = new PolarisInstanceTransformer(); + DefaultInstance instance = new DefaultInstance(); + instance.setZone("zone"); + PolarisServiceInstance polarisServiceInstance = new PolarisServiceInstance(instance); + Instance instance1 = polarisInstanceTransformer.transform(polarisServiceInstance); + assertThat(instance1.getZone()).isEqualTo("zone"); + } +} diff --git a/spring-cloud-tencent-coverage/pom.xml b/spring-cloud-tencent-coverage/pom.xml index 7a566190e..433df7c72 100644 --- a/spring-cloud-tencent-coverage/pom.xml +++ b/spring-cloud-tencent-coverage/pom.xml @@ -64,6 +64,12 @@ spring-cloud-starter-tencent-polaris-config + + com.tencent.cloud + spring-cloud-starter-tencent-discovery-adapter-plugin + ${revision} + + com.tencent.cloud spring-cloud-tencent-featureenv-plugin diff --git a/spring-cloud-tencent-dependencies/pom.xml b/spring-cloud-tencent-dependencies/pom.xml index 7b9450be9..b806520ad 100644 --- a/spring-cloud-tencent-dependencies/pom.xml +++ b/spring-cloud-tencent-dependencies/pom.xml @@ -70,10 +70,10 @@ - 1.11.0-2020.0.6-SNAPSHOT + 1.10.3-2020.0.6 - 1.11.3-SNAPSHOT + 1.11.3 31.0.1-jre 1.2.11 4.5.1 @@ -162,6 +162,12 @@ + + com.tencent.cloud + spring-cloud-starter-tencent-discovery-adapter-plugin + ${revision} + + com.tencent.cloud spring-cloud-tencent-featureenv-plugin @@ -263,6 +269,7 @@ ${system-stubs-jupiter.version} test + diff --git a/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-callee-service-a/pom.xml b/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-callee-service-a/pom.xml new file mode 100644 index 000000000..d9cef02f8 --- /dev/null +++ b/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-callee-service-a/pom.xml @@ -0,0 +1,61 @@ + + + + multiple-discovery-nacos-example + com.tencent.cloud + ${revision} + ../pom.xml + + 4.0.0 + + nacos-callee-service-a + + + + org.springframework.boot + spring-boot-starter-web + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + 2021.1 + + + + org.springframework.cloud + spring-cloud-starter-bootstrap + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + org.apache.maven.plugins + maven-source-plugin + 3.2.0 + + + attach-sources + + jar + + + + + + + \ No newline at end of file diff --git a/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-callee-service-a/src/main/java/com/tencent/cloud/multiple/discovery/nacos/NacosCalleeServiceA.java b/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-callee-service-a/src/main/java/com/tencent/cloud/multiple/discovery/nacos/NacosCalleeServiceA.java new file mode 100644 index 000000000..3e2152dd6 --- /dev/null +++ b/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-callee-service-a/src/main/java/com/tencent/cloud/multiple/discovery/nacos/NacosCalleeServiceA.java @@ -0,0 +1,34 @@ +/* + * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package com.tencent.cloud.multiple.discovery.nacos; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * Circuit breaker example callee application. + * + * @author Haotian Zhang + */ +@SpringBootApplication +public class NacosCalleeServiceA { + + public static void main(String[] args) { + SpringApplication.run(NacosCalleeServiceA.class, args); + } +} diff --git a/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-callee-service-a/src/main/java/com/tencent/cloud/multiple/discovery/nacos/NacosCalleeServiceAController.java b/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-callee-service-a/src/main/java/com/tencent/cloud/multiple/discovery/nacos/NacosCalleeServiceAController.java new file mode 100644 index 000000000..f325e14e1 --- /dev/null +++ b/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-callee-service-a/src/main/java/com/tencent/cloud/multiple/discovery/nacos/NacosCalleeServiceAController.java @@ -0,0 +1,50 @@ +/* + * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + */ + +package com.tencent.cloud.multiple.discovery.nacos; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * Service B Controller. + * + * @author Haotian Zhang + */ +@RestController +@RequestMapping("/example/service/b") +public class NacosCalleeServiceAController { + + /** + * Get service information. + * + * @return service information + */ + @GetMapping("/info") + public String info() { + return "hello world ! I'm a service B1"; + } + + @GetMapping("/health") + public String health() { + System.out.println("health check: 200 instance"); + return "hello world ! I'm a service B1"; + } + +} diff --git a/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-callee-service-a/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-callee-service-a/src/main/resources/bootstrap.yml new file mode 100644 index 000000000..654ef41a5 --- /dev/null +++ b/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-callee-service-a/src/main/resources/bootstrap.yml @@ -0,0 +1,16 @@ +server: + port: 48082 +spring: + application: + name: NacosCalleeService + cloud: + polaris: + address: grpc://183.47.111.80:8091 + namespace: default + enabled: true + stat: + enabled: true + port: 28083 + nacos: + discovery: + server-addr: 127.0.0.1:8848 diff --git a/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-callee-service-b/pom.xml b/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-callee-service-b/pom.xml new file mode 100644 index 000000000..a2e90b47a --- /dev/null +++ b/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-callee-service-b/pom.xml @@ -0,0 +1,62 @@ + + + + multiple-discovery-nacos-example + com.tencent.cloud + ${revision} + ../pom.xml + + 4.0.0 + + nacos-callee-service-b + + + + org.springframework.boot + spring-boot-starter-web + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + 2021.1 + + + + org.springframework.cloud + spring-cloud-starter-bootstrap + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + org.apache.maven.plugins + maven-source-plugin + 3.2.0 + + + attach-sources + + jar + + + + + + + + \ No newline at end of file diff --git a/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-callee-service-b/src/main/java/com/tencent/cloud/multiple/discovery/nacos/NacosCalleeServiceB.java b/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-callee-service-b/src/main/java/com/tencent/cloud/multiple/discovery/nacos/NacosCalleeServiceB.java new file mode 100644 index 000000000..8e4aa86d4 --- /dev/null +++ b/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-callee-service-b/src/main/java/com/tencent/cloud/multiple/discovery/nacos/NacosCalleeServiceB.java @@ -0,0 +1,34 @@ +/* + * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package com.tencent.cloud.multiple.discovery.nacos; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * Circuit breaker example callee application. + * + * @author Haotian Zhang + */ +@SpringBootApplication +public class NacosCalleeServiceB { + + public static void main(String[] args) { + SpringApplication.run(NacosCalleeServiceB.class, args); + } +} diff --git a/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-callee-service-b/src/main/java/com/tencent/cloud/multiple/discovery/nacos/NacosCalleeServiceBController.java b/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-callee-service-b/src/main/java/com/tencent/cloud/multiple/discovery/nacos/NacosCalleeServiceBController.java new file mode 100644 index 000000000..cae686fbe --- /dev/null +++ b/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-callee-service-b/src/main/java/com/tencent/cloud/multiple/discovery/nacos/NacosCalleeServiceBController.java @@ -0,0 +1,54 @@ +/* + * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + */ + +package com.tencent.cloud.multiple.discovery.nacos; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +/** + * Service B Controller. + * + * @author Haotian Zhang + */ +@RestController +@RequestMapping("/example/service/b") +public class NacosCalleeServiceBController { + + /** + * Get service information. + * + * @return service information + */ + @GetMapping("/info") + @ResponseStatus(code = HttpStatus.BAD_GATEWAY) + public String info() { + return "BAD_GATEWAY ! from service B2"; + } + + @GetMapping("/health") + @ResponseStatus(value = HttpStatus.BAD_GATEWAY, reason = "failed for call my service") + public String health() { + System.out.println("health check: 502 instance"); + return "hello world ! I'm a service B1"; + } + +} diff --git a/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-callee-service-b/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-callee-service-b/src/main/resources/bootstrap.yml new file mode 100644 index 000000000..76c1bc568 --- /dev/null +++ b/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-callee-service-b/src/main/resources/bootstrap.yml @@ -0,0 +1,17 @@ +server: + port: 48081 +spring: + application: + name: NacosCalleeService + cloud: + polaris: + address: grpc://183.47.111.80:8091 + namespace: default + enabled: true + stat: + enabled: true + port: 28083 + nacos: + discovery: + server-addr: 127.0.0.1:8848 + diff --git a/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-discovery-caller/pom.xml b/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-discovery-caller/pom.xml new file mode 100644 index 000000000..e05a6935c --- /dev/null +++ b/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-discovery-caller/pom.xml @@ -0,0 +1,86 @@ + + + + multiple-discovery-nacos-example + com.tencent.cloud + ${revision} + ../pom.xml + + 4.0.0 + + nacos-discovery-caller + + + + org.springframework.boot + spring-boot-starter-web + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + 2021.1 + + + + com.tencent.cloud + spring-cloud-starter-tencent-polaris-router + + + + com.tencent.cloud + spring-cloud-starter-tencent-discovery-adapter-plugin + + + + com.tencent.cloud + spring-cloud-starter-tencent-polaris-circuitbreaker + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + + org.springframework.cloud + spring-cloud-starter-loadbalancer + + + + org.springframework.cloud + spring-cloud-starter-bootstrap + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + org.apache.maven.plugins + maven-source-plugin + 3.2.0 + + + attach-sources + + jar + + + + + + + \ No newline at end of file diff --git a/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-discovery-caller/src/main/java/com/tencent/cloud/multiple/discovery/nacos/NacosCallerService.java b/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-discovery-caller/src/main/java/com/tencent/cloud/multiple/discovery/nacos/NacosCallerService.java new file mode 100644 index 000000000..dabb5ac98 --- /dev/null +++ b/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-discovery-caller/src/main/java/com/tencent/cloud/multiple/discovery/nacos/NacosCallerService.java @@ -0,0 +1,36 @@ +/* + * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package com.tencent.cloud.multiple.discovery.nacos; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.openfeign.EnableFeignClients; + +/** + * Circuit breaker example callee application. + * + * @author Haotian Zhang + */ +@SpringBootApplication +@EnableFeignClients +public class NacosCallerService { + + public static void main(String[] args) { + SpringApplication.run(NacosCallerService.class, args); + } +} diff --git a/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-discovery-caller/src/main/java/com/tencent/cloud/multiple/discovery/nacos/NacosCallerServiceController.java b/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-discovery-caller/src/main/java/com/tencent/cloud/multiple/discovery/nacos/NacosCallerServiceController.java new file mode 100644 index 000000000..6224592c8 --- /dev/null +++ b/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-discovery-caller/src/main/java/com/tencent/cloud/multiple/discovery/nacos/NacosCallerServiceController.java @@ -0,0 +1,42 @@ +/* + * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package com.tencent.cloud.multiple.discovery.nacos; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * NacosCallerServiceController. + * + * @author sean yu + */ +@RestController +@RequestMapping("/example/service/a") +public class NacosCallerServiceController { + + @Autowired + private ProviderB polarisServiceB; + + @GetMapping("/getBServiceInfo") + public String getBServiceInfoFallbackFromCode() { + return polarisServiceB.info(); + } + +} diff --git a/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-discovery-caller/src/main/java/com/tencent/cloud/multiple/discovery/nacos/ProviderB.java b/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-discovery-caller/src/main/java/com/tencent/cloud/multiple/discovery/nacos/ProviderB.java new file mode 100644 index 000000000..fbd226bda --- /dev/null +++ b/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-discovery-caller/src/main/java/com/tencent/cloud/multiple/discovery/nacos/ProviderB.java @@ -0,0 +1,38 @@ +/* + * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package com.tencent.cloud.multiple.discovery.nacos; + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; + +/** + * Circuit breaker example callee provider. + * + * @author sean yu + */ +@FeignClient(name = "NacosCalleeService") +public interface ProviderB { + + /** + * Get info of service B. + * + * @return info of service B + */ + @GetMapping("/example/service/b/info") + String info(); +} diff --git a/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-discovery-caller/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-discovery-caller/src/main/resources/bootstrap.yml new file mode 100644 index 000000000..3133ebf47 --- /dev/null +++ b/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/nacos-discovery-caller/src/main/resources/bootstrap.yml @@ -0,0 +1,26 @@ +server: + port: 48080 +spring: + application: + name: NacosCallerService + cloud: + polaris: + address: grpc://183.47.111.80:8091 + namespace: default + enabled: true + loadbalancer: + enabled: true + circuitbreaker: + enabled: true + nacos: + discovery: + server-addr: 127.0.0.1:8848 + +feign: + circuitbreaker: + enabled: true + +logging: + level: + root: info + com.tencent.cloud: debug \ No newline at end of file diff --git a/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/pom.xml b/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/pom.xml new file mode 100644 index 000000000..fea82d029 --- /dev/null +++ b/spring-cloud-tencent-examples/multiple-discovery-example/multiple-discovery-nacos-example/pom.xml @@ -0,0 +1,21 @@ + + + + multiple-discovery-example + com.tencent.cloud + ${revision} + ../pom.xml + + 4.0.0 + + multiple-discovery-nacos-example + + pom + + nacos-callee-service-a + nacos-callee-service-b + nacos-discovery-caller + + \ No newline at end of file diff --git a/spring-cloud-tencent-examples/multiple-discovery-example/pom.xml b/spring-cloud-tencent-examples/multiple-discovery-example/pom.xml new file mode 100644 index 000000000..7586bb6d7 --- /dev/null +++ b/spring-cloud-tencent-examples/multiple-discovery-example/pom.xml @@ -0,0 +1,20 @@ + + + + spring-cloud-tencent-examples + com.tencent.cloud + ${revision} + ../pom.xml + + 4.0.0 + + multiple-discovery-example + Spring Cloud Starter Tencent Multiple Discovery Example + pom + + + multiple-discovery-nacos-example + + \ No newline at end of file diff --git a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-feign-example/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-feign-example/src/main/resources/bootstrap.yml index 3378ae635..7477c3316 100644 --- a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-feign-example/src/main/resources/bootstrap.yml +++ b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-feign-example/src/main/resources/bootstrap.yml @@ -12,25 +12,10 @@ spring: enabled: true circuitbreaker: enabled: true -# stat: -# enabled: true -# port: 28081 -# tencent: -# rpc-enhancement: -# enabled: true -# reporter: -# ignore-internal-server-error: true -# series: server_error -# statuses: gateway_timeout, bad_gateway, service_unavailable feign: circuitbreaker: enabled: true -# compression: -# request: -# enabled: false -# mime-types: text/xml,application/xml,application/json -# min-request-size: 2048 logging: level: diff --git a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-resttemplate-example/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-resttemplate-example/src/main/resources/bootstrap.yml index 16fa8bd3b..720c3df80 100644 --- a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-resttemplate-example/src/main/resources/bootstrap.yml +++ b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-resttemplate-example/src/main/resources/bootstrap.yml @@ -12,16 +12,6 @@ spring: enabled: true circuitbreaker: enabled: true -# stat: -# enabled: true -# port: 28081 -# tencent: -# rpc-enhancement: -# enabled: true -# reporter: -# ignore-internal-server-error: true -# series: server_error -# statuses: gateway_timeout, bad_gateway, service_unavailable logging: level: diff --git a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-webclient-example/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-webclient-example/src/main/resources/bootstrap.yml index f84dffdea..7e75556f3 100644 --- a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-webclient-example/src/main/resources/bootstrap.yml +++ b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-webclient-example/src/main/resources/bootstrap.yml @@ -12,16 +12,6 @@ spring: enabled: true circuitbreaker: enabled: true -# stat: -# enabled: true -# port: 28081 -# tencent: -# rpc-enhancement: -# enabled: true -# reporter: -# ignore-internal-server-error: true -# series: server_error -# statuses: gateway_timeout, bad_gateway, service_unavailable logging: level: diff --git a/spring-cloud-tencent-examples/pom.xml b/spring-cloud-tencent-examples/pom.xml index 98b89c5a2..c4ab03a30 100644 --- a/spring-cloud-tencent-examples/pom.xml +++ b/spring-cloud-tencent-examples/pom.xml @@ -16,6 +16,7 @@ Examples of Spring Cloud Tencent + multiple-discovery-example polaris-discovery-example polaris-ratelimit-example polaris-circuitbreaker-example diff --git a/spring-cloud-tencent-plugin-starters/pom.xml b/spring-cloud-tencent-plugin-starters/pom.xml index 6487f9a89..bc2f153b9 100644 --- a/spring-cloud-tencent-plugin-starters/pom.xml +++ b/spring-cloud-tencent-plugin-starters/pom.xml @@ -17,6 +17,7 @@ spring-cloud-tencent-featureenv-plugin spring-cloud-tencent-gateway-plugin + spring-cloud-starter-tencent-discovery-adapter-plugin diff --git a/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-discovery-adapter-plugin/pom.xml b/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-discovery-adapter-plugin/pom.xml new file mode 100644 index 000000000..d33b5dd57 --- /dev/null +++ b/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-discovery-adapter-plugin/pom.xml @@ -0,0 +1,42 @@ + + + + spring-cloud-tencent-plugin-starters + com.tencent.cloud + ${revision} + ../pom.xml + + 4.0.0 + + spring-cloud-starter-tencent-discovery-adapter-plugin + Spring Cloud Starter Tencent Discovery Adapter Plugin + + + + + com.tencent.cloud + spring-cloud-starter-tencent-polaris-router + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + 2021.1 + test + + + + org.springframework.boot + spring-boot-starter-test + test + + + + org.mockito + mockito-inline + test + + + diff --git a/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-discovery-adapter-plugin/src/main/java/com/tencent/cloud/plugin/discovery/adapter/config/NacosDiscoveryAdapterAutoConfiguration.java b/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-discovery-adapter-plugin/src/main/java/com/tencent/cloud/plugin/discovery/adapter/config/NacosDiscoveryAdapterAutoConfiguration.java new file mode 100644 index 000000000..08aaf6651 --- /dev/null +++ b/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-discovery-adapter-plugin/src/main/java/com/tencent/cloud/plugin/discovery/adapter/config/NacosDiscoveryAdapterAutoConfiguration.java @@ -0,0 +1,52 @@ +/* + * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + */ + +package com.tencent.cloud.plugin.discovery.adapter.config; + +import com.tencent.cloud.plugin.discovery.adapter.transformer.NacosInstanceTransformer; +import com.tencent.cloud.polaris.router.config.ConditionalOnPolarisRouterEnabled; +import com.tencent.cloud.polaris.router.config.LoadBalancerConfiguration; +import com.tencent.cloud.polaris.router.spi.InstanceTransformer; + +import org.springframework.boot.autoconfigure.AutoConfigureBefore; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * NacosDiscoveryAdapterAutoConfiguration. + * + * @author sean yu + */ +@Configuration(proxyBeanMethods = false) +@ConditionalOnDiscoveryEnabled +@AutoConfigureBefore(LoadBalancerConfiguration.class) +public class NacosDiscoveryAdapterAutoConfiguration { + + + @Bean + @ConditionalOnMissingBean + @ConditionalOnPolarisRouterEnabled + @ConditionalOnClass(name = "com.alibaba.cloud.nacos.NacosServiceInstance") + public InstanceTransformer instanceTransformer() { + return new NacosInstanceTransformer(); + } + +} 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/NacosInstanceTransformer.java b/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-discovery-adapter-plugin/src/main/java/com/tencent/cloud/plugin/discovery/adapter/transformer/NacosInstanceTransformer.java new file mode 100644 index 000000000..498040c04 --- /dev/null +++ b/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-discovery-adapter-plugin/src/main/java/com/tencent/cloud/plugin/discovery/adapter/transformer/NacosInstanceTransformer.java @@ -0,0 +1,50 @@ +/* + * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + */ + +package com.tencent.cloud.plugin.discovery.adapter.transformer; + +import com.tencent.cloud.polaris.router.spi.InstanceTransformer; +import com.tencent.polaris.api.pojo.DefaultInstance; +import org.apache.commons.lang.StringUtils; + +import org.springframework.cloud.client.ServiceInstance; + +/** + * NacosInstanceTransformer. + * + * @author sean yu + */ +public class NacosInstanceTransformer implements InstanceTransformer { + + @Override + public void transformCustom(DefaultInstance instance, ServiceInstance serviceInstance) { + if ("com.alibaba.cloud.nacos.NacosServiceInstance".equals(serviceInstance.getClass().getName())) { + String nacosWeight = serviceInstance.getMetadata().get("nacos.weight"); + instance.setWeight( + StringUtils.isBlank(nacosWeight) ? 100 : (int) Double.parseDouble(nacosWeight) * 100 + ); + String nacosHealthy = serviceInstance.getMetadata().get("nacos.healthy"); + instance.setHealthy( + !StringUtils.isBlank(nacosHealthy) && Boolean.parseBoolean(nacosHealthy) + ); + String nacosInstanceId = serviceInstance.getMetadata().get("nacos.instanceId"); + instance.setId(nacosInstanceId); + } + } + +} diff --git a/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-discovery-adapter-plugin/src/main/resources/META-INF/spring.factories b/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-discovery-adapter-plugin/src/main/resources/META-INF/spring.factories new file mode 100644 index 000000000..34777be66 --- /dev/null +++ b/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-discovery-adapter-plugin/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + com.tencent.cloud.plugin.discovery.adapter.config.NacosDiscoveryAdapterAutoConfiguration diff --git a/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-discovery-adapter-plugin/src/test/java/com/tencent/cloud/plugin/discovery/adapter/config/NacosDiscoveryAdapterAutoConfigurationTest.java b/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-discovery-adapter-plugin/src/test/java/com/tencent/cloud/plugin/discovery/adapter/config/NacosDiscoveryAdapterAutoConfigurationTest.java new file mode 100644 index 000000000..cae2a60fd --- /dev/null +++ b/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-discovery-adapter-plugin/src/test/java/com/tencent/cloud/plugin/discovery/adapter/config/NacosDiscoveryAdapterAutoConfigurationTest.java @@ -0,0 +1,51 @@ +/* + * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + */ + +package com.tencent.cloud.plugin.discovery.adapter.config; + +import com.tencent.cloud.plugin.discovery.adapter.transformer.NacosInstanceTransformer; +import com.tencent.cloud.polaris.router.transformer.PolarisInstanceTransformer; +import org.junit.jupiter.api.Test; + +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.cloud.client.loadbalancer.LoadBalancerAutoConfiguration; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * NacosDiscoveryAdapterAutoConfigurationTest. + * + * @author sean yu + */ +public class NacosDiscoveryAdapterAutoConfigurationTest { + + private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of( + NacosDiscoveryAdapterAutoConfiguration.class, + LoadBalancerAutoConfiguration.class + )); + + @Test + public void testDefaultInitialization() { + this.contextRunner.run(context -> { + assertThat(context).hasSingleBean(NacosInstanceTransformer.class); + assertThat(context).doesNotHaveBean(PolarisInstanceTransformer.class); + }); + } +} diff --git a/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-discovery-adapter-plugin/src/test/java/com/tencent/cloud/plugin/discovery/adapter/config/NacosInstanceTransformerTest.java b/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-discovery-adapter-plugin/src/test/java/com/tencent/cloud/plugin/discovery/adapter/config/NacosInstanceTransformerTest.java new file mode 100644 index 000000000..dbb41f346 --- /dev/null +++ b/spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-discovery-adapter-plugin/src/test/java/com/tencent/cloud/plugin/discovery/adapter/config/NacosInstanceTransformerTest.java @@ -0,0 +1,66 @@ +/* + * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + */ + +package com.tencent.cloud.plugin.discovery.adapter.config; + +import java.util.HashMap; + +import com.alibaba.cloud.nacos.NacosServiceInstance; +import com.tencent.cloud.common.util.ApplicationContextAwareUtils; +import com.tencent.cloud.plugin.discovery.adapter.transformer.NacosInstanceTransformer; +import com.tencent.polaris.api.pojo.Instance; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.mockito.MockedStatic; +import org.mockito.Mockito; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * NacosInstanceTransformerTest. + * + * @author sean yu + */ +public class NacosInstanceTransformerTest { + + private static MockedStatic mockedApplicationContextAwareUtils; + + @BeforeAll + public static void beforeAll() { + mockedApplicationContextAwareUtils = Mockito.mockStatic(ApplicationContextAwareUtils.class); + mockedApplicationContextAwareUtils.when(() -> ApplicationContextAwareUtils.getProperties("spring.cloud.polaris.namespace")) + .thenReturn("default"); + mockedApplicationContextAwareUtils.when(() -> ApplicationContextAwareUtils.getProperties("spring.cloud.polaris.service")) + .thenReturn("test"); + } + + + @Test + public void test() { + NacosInstanceTransformer nacosInstanceTransformer = new NacosInstanceTransformer(); + NacosServiceInstance nacosServiceInstance = new NacosServiceInstance(); + nacosServiceInstance.setMetadata(new HashMap() {{ + put("nacos.weight", "0.01"); + put("nacos.healthy", "true"); + put("nacos.instanceId", "xxx"); + }}); + Instance instance = nacosInstanceTransformer.transform(nacosServiceInstance); + assertThat(instance.isHealthy()).isEqualTo(true); + } + +} diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/ReporterUtils.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/ReporterUtils.java index d56ecf328..c7e97404a 100644 --- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/ReporterUtils.java +++ b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/ReporterUtils.java @@ -72,6 +72,11 @@ public final class ReporterUtils { resultRequest.setRetCode(response.status()); resultRequest.setRetStatus(retStatus); resultRequest.setDelay(delay); + String scheme = uri.getScheme(); + if (StringUtils.isBlank(scheme)) { + scheme = "http"; + } + resultRequest.setProtocol(scheme); String sourceNamespace = MetadataContext.LOCAL_NAMESPACE; String sourceService = MetadataContext.LOCAL_SERVICE; if (StringUtils.isNotBlank(sourceNamespace) && StringUtils.isNotBlank(sourceService)) {