使用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
相关推荐
power-辰南2 天前
基于 Spring Cloud + Sentinel 的全面流量治理方案
spring·spring cloud·sentinel·流量治理
蔚一3 天前
微服务SpringCloudAlibaba组件sentinel教程【详解sentinel的使用以及流量控制、熔断降级、热点参数限流等,附有示例+代码】
java·spring boot·后端·微服务·架构·sentinel·intellij-idea
华农第一蒟蒻3 天前
Sentinel
java·开发语言·sentinel
qw9494 天前
Redis 09章——哨兵(sentinel)
数据库·redis·sentinel
FG.4 天前
微服务保护---Sentinel
微服务·sentinel
Xwzzz_5 天前
SpringCloud中Sentinel基础场景和异常处理
java·spring cloud·sentinel
bing_1585 天前
Springboot 中如何使用Sentinel
spring boot·sentinel
power-辰南7 天前
微服务限流策略与性能优化全解析
性能优化·sentinel·springcloud·流量监控·流量治理
WeiLai11129 天前
Redis Sentinel(哨兵)模式介绍
redis·bootstrap·sentinel
励碼10 天前
解决 Sentinel 控制台无法显示 OpenFeign 资源的问题
spring boot·spring cloud·sentinel·bug·openfeign