使用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
相关推荐
会飞的大可5 天前
Redis Sentinel 高可用方案在WMS仓储管理系统的应用
redis·sentinel
zs宝来了7 天前
Redis 哨兵机制:Sentinel 原理与高可用实现
redis·sentinel·高可用·源码解析·哨兵
梵得儿SHI7 天前
SpringCloud 秒杀系统生产级落地:Sentinel+Redis 联合优化,从限流防刷到库存闭环,彻底解决超卖 / 宕机 / 恶意刷
redis·spring cloud·sentinel·分布式限流·百万级·瞬时高并发·产级秒杀系统解决方案
8Qi89 天前
Redis哨兵模式(Sentinel)深度解析
java·数据库·redis·分布式·缓存·sentinel
无名-CODING9 天前
Java 爬虫零基础入门:从 HTTP 到 Jsoup 实战
spring cloud·gateway·sentinel
会飞的大可10 天前
Spring Cloud Alibaba全景:Nacos、Sentinel、Seata整合实战
sentinel·wpf
无名-CODING10 天前
SpringCloud 网关与熔断:Gateway + Sentinel 快速入门
spring cloud·gateway·sentinel
yoyo_zzm14 天前
SpringCloud Gateway 集成 Sentinel 详解 及实现动态监听Nacos规则配置实时更新流控规则
spring cloud·gateway·sentinel
短剑重铸之日15 天前
深入理解Sentinel: 01 一次服务雪崩问题排查经历
java·sentinel·降级熔断