From 79dc92805a42b8fe1e94d2e1ab10be3f08406ea5 Mon Sep 17 00:00:00 2001 From: Bunny <1319900154@qq.com> Date: Sun, 9 Feb 2025 21:32:31 +0800 Subject: [PATCH] =?UTF-8?q?feat(openFeign):=20SentinelResource=E6=B3=A8?= =?UTF-8?q?=E8=A7=A3=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/bunny/controller/PropertiesController.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/service/cloud-demo1/src/main/java/cn/bunny/controller/PropertiesController.java b/service/cloud-demo1/src/main/java/cn/bunny/controller/PropertiesController.java index 1e25b73..dd364a4 100644 --- a/service/cloud-demo1/src/main/java/cn/bunny/controller/PropertiesController.java +++ b/service/cloud-demo1/src/main/java/cn/bunny/controller/PropertiesController.java @@ -2,6 +2,7 @@ package cn.bunny.controller; import cn.bunny.feign.CloudFeignClient; import cn.bunny.properties.OrderProperties; +import com.alibaba.csp.sentinel.annotation.SentinelResource; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.beans.factory.annotation.Autowired; @@ -24,15 +25,24 @@ public class PropertiesController { private CloudFeignClient cloudFeignClient; @GetMapping("config") + @SentinelResource(value = "getConfig", fallback = "getConfigFallBack") @Operation(summary = "获取云端配置属性", description = "获取云端配置属性") public String getConfig() { return "timeout:" + orderProperties.getTimeout() + ";autoConfirm:" + orderProperties.getConfirm() + ";dbUrl:" + orderProperties.getDbUrl(); } + /** + * 当获取速度过快时会走这个 + */ + public String getConfigFallBack() { + return "获取云端配置属性,操作过快。。。"; + } + @Operation(summary = "远程调用拦截token", description = "远程调用拦截token") @GetMapping("product") - String getProduct(@RequestParam("id") Long id) { + public String getProduct(@RequestParam("id") Long id) { // TokenRequestInterceptor 会将内容放到请求头中之后在另一个微服务中查看请求头即可 return cloudFeignClient.getProduct(id); } + }