package com.example.controller;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.example.entity.Product;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("product")
public class ProductController {
@Value("${server.port}")
private Integer serverPort;
@GetMapping("/{proId}")
@SentinelResource(value = "getById",blockHandler = "handleBlock",fallback = "handleFallback")
public String getById(@PathVariable("proId") Integer proId){
Product product = new Product(proId,"保温杯",69.9F,"images/cup.png");
System.out.println("商品服务"+serverPort+"正在查询商品:"+proId);
int i = 10/0;
return product.toString();
}
/**
* 违背流控规则,blockHandler
* product/{proId}
* 有流控规则,QPS <= 1
* 若超过流量阈值,blockHandler
*/
public String handleBlock(@PathVariable("proId") Integer proId, BlockException exception) {
return "商品查询请求QPS>1,超过流量阈值";
}
/**
* 业务有异常,fallback
*/
public String handleFallback(@PathVariable("proId") Integer proId,Throwable e) {
Product product = new Product();
product.setProductId(proId);
product.setProducutName("保温杯");
return "[fallback]商品查询的信息是:" + product;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
003 springCloudAlibaba Sentinel blockHandler fallback
共39个文件
java:10个
xml:8个
gitignore:4个
0 下载量 69 浏览量
2024-04-29
22:42:53
上传
评论
收藏 198KB RAR 举报
温馨提示
003 springCloudAlibaba Sentinel blockHandler fallback
资源推荐
资源详情
资源评论
收起资源包目录
003 springCloudAlibaba Sentinel (blockHandler fallback).rar (39个子文件)
springCloudAlibaba
HELP.md 430B
mvnw.cmd 7KB
pom.xml 2KB
.mvn
wrapper
maven-wrapper.properties 233B
maven-wrapper.jar 61KB
productServer
HELP.md 860B
mvnw.cmd 7KB
pom.xml 2KB
src
test
java
com
example
ProductServerApplicationTests.java 219B
main
resources
templates
static
application.yaml 380B
java
com
example
ServletInitializer.java 423B
ProductServerApplication.java 426B
controller
ProductController.java 2KB
entity
Product.java 2KB
.mvn
wrapper
maven-wrapper.properties 233B
maven-wrapper.jar 61KB
mvnw 11KB
.gitignore 395B
.idea
jarRepositories.xml 874B
workspace.xml 8KB
misc.xml 782B
compiler.xml 1KB
.gitignore 184B
encodings.xml 521B
mvnw 11KB
.gitignore 395B
orderServer
HELP.md 860B
mvnw.cmd 7KB
pom.xml 2KB
src
test
java
com
example
OrderServerApplicationTests.java 217B
main
resources
templates
static
application.yaml 373B
java
com
example
ServletInitializer.java 421B
controller
ProductClient.java 399B
OrderController.java 1KB
OrderServerApplication.java 505B
.mvn
wrapper
maven-wrapper.properties 233B
maven-wrapper.jar 61KB
mvnw 11KB
.gitignore 395B
共 39 条
- 1
资源评论
简洁冬冬
- 粉丝: 1085
- 资源: 34
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功