使用sentinel进行服务熔断和服务降级

注意sentinel要与项目能ping通,若sentinel在云服务器上,而项目在本地,则无法连接

1、使用docker安装sentinel(可以上网搜镜像文件)

注意:端口应该为8858,账号和密码为sentinel

2、使用ip:8858访问sentinel页面,可以设置服务的熔断和降级

3、在项目父工程冲,引入依赖(注意这个type和scope与子工程有关,必须要写)

java 复制代码
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Hoxton.SR10</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>2.2.5.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

4、在项目子工程中,引入依赖

java 复制代码
<!--        sentinel依赖-->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
        </dependency>

5、显式添加 Hibernate 和 Validator 依赖,可以避免sentinel依赖导致启动失败

java 复制代码
<!--        显式添加 Hibernate 和 Validator 依赖,可以避免sentinel依赖导致启动失败-->
        <dependency>
            <groupId>org.hibernate.validator</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>6.1.5.Final</version> <!-- 例如 6.1.5.Final -->
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>2.0.1.Final</version> <!-- 例如 2.0.1.Final -->
            <!-- 注意:通常 Hibernate Validator 会包含 validation-api 的传递依赖,但显式添加可以避免潜在问题 -->
        </dependency>

6、在项目子工程中,yml配置:

java 复制代码
spring:
  cloud:
    sentinel:
      transport:
        dashboard: ip:8858
相关推荐
W.Buffer1 天前
SpringCloud-Sentinel实战与源码分析:从流量防护到底层实现
spring·spring cloud·sentinel
TM_soul1 天前
Sentinel安装部署
sentinel
不能再留遗憾了4 天前
【SpringCloud】Sentinel
spring·spring cloud·sentinel
Chan165 天前
流量安全优化:基于 Sentinel 实现网站流量控制和熔断
java·spring boot·安全·sentinel·intellij-idea·进程
@HNUSTer6 天前
基于 GEE 的 Sentinel-2 光谱、指数、纹理特征提取与 Sentinel-1 SAR 数据处理
云计算·sentinel·数据集·遥感大数据·gee·云平台·sar
@HNUSTer9 天前
基于 GEE 平台用 Sentinel-1 SAR 数据实现山区潜在滑坡检测
云计算·sentinel·数据集·遥感大数据·gee·云平台·sar
还是鼠鼠11 天前
《黑马商城》微服务保护-详细介绍【简单易懂注释版】
java·spring boot·spring·spring cloud·sentinel·maven
月夕·花晨14 天前
Gateway-过滤器
java·分布式·spring·spring cloud·微服务·gateway·sentinel
非凡ghost16 天前
Hard Disk Sentinel(固态硬盘监控) 多语便携版
windows·sentinel·软件需求
柳贯一(逆流河版)19 天前
Sentinel 深度解析:限流与熔断降级的微服务稳定性保障实践
微服务·架构·sentinel