使用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
相关推荐
Fang fan2 天前
Redis基础数据结构
数据结构·数据库·redis·缓存·bootstrap·sentinel
回到原点的码农3 天前
SpringCloud Gateway 集成 Sentinel 详解 及实现动态监听Nacos规则配置实时更新流控规则
spring cloud·gateway·sentinel
没有bug.的程序员4 天前
黑客僵尸网络的降维打击:Spring Cloud Gateway 自定义限流剿杀 Sentinel 内存黑洞
java·网络·spring·gateway·sentinel
xiaolingting6 天前
Gateway 网关流控与限流架构指南
spring cloud·架构·gateway·sentinel
sc_爬坑之路7 天前
redis windows环境配置读写分离:一主一从 + Sentinel 完整实战
windows·redis·sentinel
sc_爬坑之路7 天前
Linux 部署 Redis:一主一从 + Sentinel 完整实战
linux·redis·sentinel
杜子不疼.7 天前
Spring Cloud 熔断降级详解:用 “保险丝“ 类比,Sentinel 实战教程
人工智能·spring·spring cloud·sentinel
yc_xym9 天前
Redis哨兵(Sentinel)机制
数据库·redis·sentinel
Thomas.Sir9 天前
深入剖析 Sentinel:阿里开源的微服务流量防卫兵
微服务·开源·sentinel
廋到被风吹走23 天前
稳定性保障:限流降级深度解析 —— Sentinel滑动窗口算法与令牌桶实现
运维·算法·sentinel