package com.psf.springcloud.Alibaba.controller;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.psf.springcloud.Alibaba.entity.CommonResult;
import com.psf.springcloud.Alibaba.entity.User;
import lombok.extern.slf4j.Slf4j;
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;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
/**
* @ClassName: ConsumerController
* @Auther: Administrator
* @Date: 2020/6/29 13:57
* @return version 1.0
*/
@RestController
@Slf4j
public class ConsumerController {
public static final String SERVICE_URL="http://nacos-payment-provider";
@Resource
private RestTemplate restTemplate;
@RequestMapping("/consumer/fallback/{id}")
@SentinelResource(value = "fallback",fallback = "handlerFallback",blockHandler = "handler",
exceptionsToIgnore = IllegalArgumentException.class)
public CommonResult<User> fallback(@PathVariable("id") Long id) {
CommonResult<User> result = restTemplate.getForObject(SERVICE_URL + "/result/"+id, CommonResult.class,id);
if (id == 4) {
throw new IllegalArgumentException ("IllegalArgumentException,非法参数异常....");
}else if (result.getData() == null) {
throw new NullPointerException ("NullPointerException,该ID没有对应记录,空指针异常");
}
return result;
}
//fallback
public CommonResult handlerFallback(@PathVariable Long id,Throwable e) {
User payment = new User(id,"null");
return new CommonResult<>(444,"兜底异常handlerFallback,exception内容 "+e.getMessage(),payment);
}
//blockHandler
public CommonResult handler(@PathVariable Long id, BlockException blockException) {
User payment = new User(id,"null");
return new CommonResult<>(444,"被限速啦 "+blockException.getMessage(),payment);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
很多人可能会问,有了spring cloud这个微服务的框架,为什么又要使用spring cloud alibaba这个框架了?最重要的原因在于spring cloud中的几乎所有的组件都使用Netflix公司的产品,然后在其基础上做了一层封装。然而Netflix的服务发现组件Eureka已经停止更新,我们公司在使用的时候就发现过其一个细小的Bug;而其他的众多组件预计会在明年(即2020年)停止维护。所以急需其他的一些替代产品,也就是spring cloud alibaba,目前正处于蓬勃发展的态式。
资源推荐
资源详情
资源评论
收起资源包目录
SpringCloud Alibaba nacos、sentinel、seata.zip (192个子文件)
$CACHE_FILE$ 917B
workspace.xml.bak 12KB
Order.class 4KB
ConsumerController.class 4KB
Storage.class 3KB
Account.class 3KB
CommonResult.class 3KB
CommonResult.class 3KB
SentinelController.class 3KB
OrderServiceImpl.class 2KB
PaymentController.class 2KB
PaymentController.class 2KB
DataSourceProxyConfig.class 2KB
DataSourceProxyConfig.class 2KB
DataSourceProxyConfig.class 2KB
User.class 2KB
User.class 2KB
OrderNacosController.class 2KB
PaymentController.class 2KB
PaymentController.class 2KB
AccountController.class 2KB
StorageController.class 2KB
OrderController.class 1KB
OpenFeignController.class 1KB
AccountServiceImpl.class 1KB
StorageServiceImpl.class 1KB
PaymentFallbackService.class 1KB
SeataAccountMain8002.class 970B
SeataStorageMain8003.class 970B
OrderMain8001.class 949B
CustomerBlockHandler.class 946B
ConfigclientController.class 892B
ConsumerOrderMain84.class 873B
ProviderNacosMain9001.class 816B
ProviderNacosMain9005.class 816B
ProviderNacosMain9002.class 816B
ProviderNacosMain9006.class 816B
NacosConfigMain9101.class 810B
OrderNacosMain83.class 801B
SentinelMain8401.class 801B
ApplicationContextConfig.class 777B
ApplicationContextConfig.class 777B
PaymentService.class 652B
StorageService.class 621B
AccountService.class 621B
MyBatisConfig.class 530B
MyBatisConfig.class 530B
MyBatisConfig.class 530B
OrderDao.class 475B
AccountDao.class 406B
StorageDao.class 406B
AccountService.class 208B
OrderService.class 206B
StorageService.class 205B
registry.conf 1KB
registry.conf 1KB
registry.conf 1KB
registry.conf 1KB
registry.conf 1KB
registry.conf 1KB
file.conf 848B
file.conf 848B
file.conf 848B
file.conf 848B
file.conf 848B
file.conf 848B
.gitignore 0B
seata-storage-service8003.iml 81B
springspringcloud-Alibaba.iml 81B
springcloud-Alibaba.iml 81B
alibaba-provider-payment9005.iml 81B
alibaba-psf-basic.iml 81B
alibaba-consumer-nacos-order83.iml 81B
alibaba-sentinel-service8401.iml 81B
seata-order-service8001.iml 81B
alibaba-config-nacos-client9101.iml 81B
alibaba-psf-basic-1.0-SNAPSHOT.jar 5KB
ConsumerController.java 2KB
DataSourceProxyConfig.java 2KB
SentinelController.java 2KB
DataSourceProxyConfig.java 2KB
DataSourceProxyConfig.java 2KB
OrderServiceImpl.java 1KB
PaymentController.java 1KB
PaymentController.java 1KB
OrderNacosController.java 1KB
AccountController.java 982B
PaymentController.java 973B
PaymentController.java 972B
StorageController.java 950B
OpenFeignController.java 933B
SeataStorageMain8003.java 838B
OrderController.java 835B
SeataAccountMain8002.java 814B
OrderMain8001.java 812B
ConfigclientController.java 717B
AccountServiceImpl.java 701B
CustomerBlockHandler.java 675B
StorageServiceImpl.java 674B
ConsumerOrderMain84.java 655B
共 192 条
- 1
- 2
资源评论
有梦想的小弱鸡
- 粉丝: 6598
- 资源: 36
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于MFC的校园导航程序(使用最短路径dijkstra算法).rar
- Android Studio android APP 视频作为视图背景需要源代码或想了解其实现原理的可以私心我
- com.ZeroneGames.GreenProject.apk
- Python自动化开发入门教程
- 4399GameSem_116_13955_207551_6.apk
- python 3.9.19源码编译包
- php-8.2.18-Win32-vs16-x64.rar
- 字节跳动青训营-抖音项目
- SQL资料手册,语句教程,高级查询语句语法
- 上位机和串口建立 Modbus 协议进行数据传输,并使用 Mysql 数据库存储,能够实现实时温湿度显示和动态变化曲线,历史数据
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功