feat(openFeign): SentinelResource注解使用
This commit is contained in:
parent
6cb44520c3
commit
79dc92805a
|
@ -2,6 +2,7 @@ package cn.bunny.controller;
|
||||||
|
|
||||||
import cn.bunny.feign.CloudFeignClient;
|
import cn.bunny.feign.CloudFeignClient;
|
||||||
import cn.bunny.properties.OrderProperties;
|
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.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -24,15 +25,24 @@ public class PropertiesController {
|
||||||
private CloudFeignClient cloudFeignClient;
|
private CloudFeignClient cloudFeignClient;
|
||||||
|
|
||||||
@GetMapping("config")
|
@GetMapping("config")
|
||||||
|
@SentinelResource(value = "getConfig", fallback = "getConfigFallBack")
|
||||||
@Operation(summary = "获取云端配置属性", description = "获取云端配置属性")
|
@Operation(summary = "获取云端配置属性", description = "获取云端配置属性")
|
||||||
public String getConfig() {
|
public String getConfig() {
|
||||||
return "timeout:" + orderProperties.getTimeout() + ";autoConfirm:" + orderProperties.getConfirm() + ";dbUrl:" + orderProperties.getDbUrl();
|
return "timeout:" + orderProperties.getTimeout() + ";autoConfirm:" + orderProperties.getConfirm() + ";dbUrl:" + orderProperties.getDbUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当获取速度过快时会走这个
|
||||||
|
*/
|
||||||
|
public String getConfigFallBack() {
|
||||||
|
return "获取云端配置属性,操作过快。。。";
|
||||||
|
}
|
||||||
|
|
||||||
@Operation(summary = "远程调用拦截token", description = "远程调用拦截token")
|
@Operation(summary = "远程调用拦截token", description = "远程调用拦截token")
|
||||||
@GetMapping("product")
|
@GetMapping("product")
|
||||||
String getProduct(@RequestParam("id") Long id) {
|
public String getProduct(@RequestParam("id") Long id) {
|
||||||
// TokenRequestInterceptor 会将内容放到请求头中之后在另一个微服务中查看请求头即可
|
// TokenRequestInterceptor 会将内容放到请求头中之后在另一个微服务中查看请求头即可
|
||||||
return cloudFeignClient.getProduct(id);
|
return cloudFeignClient.getProduct(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue