feat(openFeign): SentinelResource注解使用

This commit is contained in:
Bunny 2025-02-09 21:32:31 +08:00
parent 6cb44520c3
commit 79dc92805a
1 changed files with 11 additions and 1 deletions

View File

@ -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);
}
}