diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d0dc805f..008d5d82f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,4 +11,5 @@ - [docs:update Polaris test environment ip.](https://github.com/Tencent/spring-cloud-tencent/pull/1011) - [feat:sct-all package is now available as a shaded uber-jar.](https://github.com/Tencent/spring-cloud-tencent/pull/1016) - [fix:fix custom fallback exception.](https://github.com/Tencent/spring-cloud-tencent/pull/1021) -- [feat:sct-all package is now available as a shaded uber-jar.](https://github.com/Tencent/spring-cloud-tencent/pull/1026) \ No newline at end of file +- [feat:sct-all package is now available as a shaded uber-jar.](https://github.com/Tencent/spring-cloud-tencent/pull/1026) +- [fix:use path parameter in `@FeignClient` for circuit-breaker.](https://github.com/Tencent/spring-cloud-tencent/pull/1030) diff --git a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/feign/PolarisCircuitBreakerNameResolver.java b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/feign/PolarisCircuitBreakerNameResolver.java index 929a71d22..9c71bc7ed 100644 --- a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/feign/PolarisCircuitBreakerNameResolver.java +++ b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/feign/PolarisCircuitBreakerNameResolver.java @@ -18,11 +18,16 @@ package com.tencent.cloud.polaris.circuitbreaker.feign; import java.lang.reflect.Method; +import java.net.URI; +import java.net.URISyntaxException; import com.tencent.cloud.common.metadata.MetadataContext; import feign.Target; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.cloud.openfeign.CircuitBreakerNameResolver; +import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.RequestMapping; import static org.springframework.core.annotation.AnnotatedElementUtils.findMergedAnnotation; @@ -34,13 +39,31 @@ import static org.springframework.core.annotation.AnnotatedElementUtils.findMerg */ public class PolarisCircuitBreakerNameResolver implements CircuitBreakerNameResolver { + private static final Logger LOG = LoggerFactory.getLogger(PolarisCircuitBreakerNameResolver.class); + @Override public String resolveCircuitBreakerName(String feignClientName, Target target, Method method) { String serviceName = target.name(); - RequestMapping requestMapping = findMergedAnnotation(method, RequestMapping.class); String path = ""; + + // Get path in @FeignClient. + if (StringUtils.hasText(target.url())) { + URI uri = null; + try { + uri = new URI(target.url()); + } + catch (URISyntaxException e) { + LOG.warn("Generate URI from url({}) in @FeignClient. failed.", target.url()); + } + if (uri != null) { + path += uri.getPath(); + } + } + + // Get path in @RequestMapping. + RequestMapping requestMapping = findMergedAnnotation(method, RequestMapping.class); if (requestMapping != null) { - path = requestMapping.path().length == 0 ? + path += requestMapping.path().length == 0 ? requestMapping.value().length == 0 ? "" : requestMapping.value()[0] : requestMapping.path()[0]; }