欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 新闻 > 焦点 > 微服务-spring cloud隔离和降级

微服务-spring cloud隔离和降级

2025/10/13 8:52:26 来源:https://blog.csdn.net/R202471/article/details/141070121  浏览:    关键词:微服务-spring cloud隔离和降级

概述

Feign整合Sentinel

添加依赖

 <!--sentinel依赖--><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-sentinel</artifactId><version>2.2.8.RELEASE</version></dependency>

配置文件

FeignClient

@Component//表示为ProductFeign提供降级逻辑
public class ProductFallbackFactory implements FallbackFactory<ProductFeign> {@Overridepublic ProductFeign create(Throwable throwable) {return new ProductFeign() {@Overridepublic Product getId(Integer pid) {System.out.println("getId降级了");Product product = new Product(0,"降级了",new BigDecimal(0.0),0);return product;}@Overridepublic String info() {return "info降级";}};}
}

Sentinel控制台

访问

持久化

Push模式

结构图

启动

把原来的sentinel关掉,启动别人写好的带有持久化的jar包

再重新访问sentinel

在这里设置各种模式就会保存下来。

添加依赖

 <dependency><groupId>com.alibaba.csp</groupId><artifactId>sentinel-datasource-nacos</artifactId><version>1.8.1</version></dependency>

修改配置文件

访问

product-flow-rules

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词