当前位置:网站首页>【微服务|Sentinel】sentinel整合openfeign
【微服务|Sentinel】sentinel整合openfeign
2022-07-01 22:29:00 【步尔斯特】
步骤
上文我们谈到sentinel的注解@SentinelResource以及其对异常兜底方案的处理。
如果对每一个接口都做各自的处理,会有诸多不便,所以我们可以整合openfeign对限流降级策略统一处理。
第一步:打开feign对sentinel的支持
feign:
sentinel:
enabled: true
第二步:编写兜底方案
import com.ossa.feign.api.producer.ProducerFeign;
import org.springframework.stereotype.Service;
/** * @author issavior */
@Service
public class ProducerFeignFallback implements ProducerFeign {
@Override
public String producerById(String id) {
String msg = "fallback限流方法";
return id + msg;
}
}
第三步:修改@FeignClient注解
import com.ossa.feign.config.FeignClientConfig;
import com.ossa.feign.fallback.ProducerFeignFallback;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
/** * @author issavior */
@FeignClient(value = "ossa-service-producer", configuration = FeignClientConfig.class,fallback = ProducerFeignFallback.class)
public interface ProducerFeign {
/** * 根据ID查询商品 * * @param id 商品的主键ID * @return 相关商品的信息 */
@GetMapping(value = "/producer/{id}")
String producerById(@PathVariable("id") String id);
}
问题
问题描述:
Caused by: java.lang.IllegalStateException: Ambiguous mapping
分析:
在feign的接口上使用@RequestMapping注解,就会导致这个问题。
Controller这一个控制层请求映射了两个方法,且在Controller中重复了,所以报错。 或者说,如果一个项目中有两个@RequestMapping(“/xxx”)完全相同就会报 java.lang.IllegalStateException,controller所在的模块依赖了client所在的模块才导致冲突的。
解决方案:
去掉@RequestMapping

边栏推荐
- Multiple smart pointers
- Convergence and disposal suggestions of some Internet exposure surfaces
- 数字货币:影响深远的创新
- [JUC learning road day 9] barrier derivatives
- El input text field word limit, beyond which the display turns red and input is prohibited
- MySQL -- index of MyISAM storage engine
- Business visualization - make your flowchart'run'up
- Congratulations on the release of friends' new book (send welfare)
- Detailed explanation of common configurations in redis configuration file [easy to understand]
- 轉載csdn文章操作
猜你喜欢

正则系列之组和范围(Groups and Ranges)

Hide the creation and use of users

数字货币:影响深远的创新

Use 3DMAX to make a chess piece

ESP自动下载电路设计

激发新动能 多地发力数字经济

vSphere+、vSAN+来了!VMware 混合云聚焦:原生、快速迁移、混合负载

Demo program implementation of QT version Huarui camera

软件测试之「 性能测试」总结,新手上路必会知识点
![Jielizhi Bluetooth headset quality control and production skills [chapter]](/img/3e/571d246d211a979e948dae1de56e93.png)
Jielizhi Bluetooth headset quality control and production skills [chapter]
随机推荐
微信个人小商店一键开通助手小程序开发
Digital currency: far-reaching innovation
[kotlin third party] coil koltin collaboration picture loading library coil glide like picture loading third party
Business visualization - make your flowchart'run'up
实在RPA:银行数字化,业务流程自动化“一小步”,贷款审核效率“一大步”
Electron学习(三)之简单交互操作
【Swoole系列1】在Swoole的世界中,你将学习到什么?
攻防演习防御体系构建之第三篇之建立实战化的安全体系
window10安装wsl(一)(WslRegisterDistribution ERROR)
Quantifiers of regular series
Advanced skills of testers: a guide to the application of unit test reports
MySQL -- index of MyISAM storage engine
Treatment of insufficient space in the root partition of armbain system
Detailed explanation of twenty common software testing methods (the most complete in History)
力扣 710. 黑名单中的随机数
转--拿来即用:分享一个检查内存泄漏的小工具
A few minutes before work, I found out V-model and The difference between sync
Programming English vocabulary notebook
Turn -- bring it and use it: share a gadget for checking memory leaks
Detailed explanation of common configurations in redis configuration file [easy to understand]