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

边栏推荐
- shell 流程控制
- Cloud Vulnerability Global Database
- 激发新动能 多地发力数字经济
- Cisco -- an external tool for WAN's concept examination
- 业务可视化-让你的流程图'Run'起来
- Happy number [fast and slow pointer of ring PROBLEMS]
- 思科--WAN 的概念考试外部工具
- Use and function of spark analyze command map join broadcast join
- 【嵌入式系统课设】单个按键控制LED灯
- Turn -- the underlying debugging principle of GDB is so simple
猜你喜欢

Stimulate new kinetic energy and promote digital economy in multiple places

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received

思科考试--路由的概念和配置考试

You probably haven't noticed the very important testing strategy in your work

Digital currency: far-reaching innovation

Programming English vocabulary notebook

Cisco test -- the concept and configuration test of routing

思科--WAN 的概念考试外部工具

【Kotlin 第三方 】coil koltin协程图片加载库Coil类似Glide的图片加载第三方

Cisco -- an external tool for WAN's concept examination
随机推荐
[kotlin third party] coil koltin collaboration picture loading library coil glide like picture loading third party
Preparation of functional test report
Redis~02 cache: how to ensure data consistency in MySQL and redis when updating data?
Business visualization - make your flowchart'run'up
Jielizhi, production line assembly link [chapter]
Data enhancement of semi supervised learning
Detailed explanation of common configurations in redis configuration file [easy to understand]
思科--高可用和高可靠网络考试
MySQL -- index of MyISAM storage engine
AirServer最新Win64位个人版投屏软件
plain framework的实际应用和扩展
window10安装wsl(一)(WslRegisterDistribution ERROR)
什么是马赛克?
众昂矿业:发展以氟化工为主的特色化工产业具有先天优势
Stimulate new kinetic energy and promote digital economy in multiple places
Contents of other parts of the map
业务可视化-让你的流程图'Run'起来
[MySQL] index creation, viewing and deletion
Flynk SQL client uses comparison and is familiar with official documents
window安装wsl(二)