当前位置:网站首页>【微服务|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

边栏推荐
- Mysql 5.7 实现 rank 排名
- 马赛克后挡板是什么?
- [MySQL] index classification
- Cisco -- highly available and reliable network examination
- Digital currency: far-reaching innovation
- YOGA27多维一体电脑,兼具出色外观与高端配置
- ECMAScript 2022 正式发布,有你了解过的吗?
- Réimpression de l'article csdn
- 正则系列之量词(Quantifiers)
- Happy number [fast and slow pointer of ring PROBLEMS]
猜你喜欢

转--利用C语言中的setjmp和longjmp,来实现异常捕获和协程

Explain JMM in detail

众昂矿业:发展以氟化工为主的特色化工产业具有先天优势
![Jielizhi Bluetooth headset quality control and production skills [chapter]](/img/ad/28e7461f8c5dc5c54a3f4da0c111ac.png)
Jielizhi Bluetooth headset quality control and production skills [chapter]

使用 EMQX Cloud 实现物联网设备一机一密验证

【嵌入式系统课设】单个按键控制LED灯
![[JUC learning road day 9] barrier derivatives](/img/7d/25a49afa470cfef5b7b383918d6a7d.png)
[JUC learning road day 9] barrier derivatives

El input text field word limit, beyond which the display turns red and input is prohibited

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

实在RPA:银行数字化,业务流程自动化“一小步”,贷款审核效率“一大步”
随机推荐
常见的二十种软件测试方法详解(史上最全)
Explain the volatile keyword
软考信息系统项目管理师_整理的十大管理过程的简写帮助记忆背诵---软考高级之信息系统项目管理师054
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received
Turn -- use setjmp and longjmp in C language to realize exception capture and collaboration
微服务服务稳定性治理
业务可视化-让你的流程图'Run'起来
Jielizhi, production line assembly link [chapter]
Treatment of insufficient space in the root partition of armbain system
Turn -- go deep into Lua scripting language, so that you can thoroughly understand the debugging principle
转载csdn文章操作
The principle, testing and Countermeasures of malicious software reverse closing EDR
Quantifiers of regular series
Reprint CSDN article operation
Some abilities can't be learned from work. Look at this article, more than 90% of peers
I graduated from college in 14 years and changed to software testing in 3 months. My monthly salary was 13.5k. At the age of 32, I finally found the right direction
Convergence and disposal suggestions of some Internet exposure surfaces
思科--高可用和高可靠网络考试
Multiple smart pointers
AirServer最新Win64位个人版投屏软件