开发者社区 > 云原生 > 中间件 > 正文

hystrix这样的默认配置针对所有接口的熔断,在sentinel上面怎么实现?

d482b2f11ec557193d318d18fdbcc916.png
我现在做sentinel替换hystrix,hystrix这样的默认配置针对所有接口的熔断,在sentinel上面怎么实现,只能每个接口上@SentinelResource定义下资源然后配置规则吗?

展开
收起
2401。 2023-08-27 17:42:54 70 0
1 条回答
写回答
取消 提交回答
  • Sentinel 提供了全局限流、熔断、降级、系统保护等功能。你可以通过以下步骤来配置全局熔断规则:

    在你的 Spring Boot 项目中,添加 sentinel-core 依赖。
    在 application.yml 配置文件中,添加如下配置:

    spring:
      cloud:
        sentinel:
          transport:
            port: 8719
            dashboard:
              enabled: false
        # 配置全局熔断规则
          default:
            circuitBreaker:
              # 熔断开关是否打开
              enabled: true
              # 最大请求数(QPS)
              maxRequest: 10
              # 熔断超时时间(单位:毫秒)
              timeoutInMilliseconds: 1000
              # 熔断重试次数
              maxRetryTimes: 3
    

    启动你的 Spring Boot 项目。
    这样,Sentinel 就会对所有接口开启熔断功能。

    当然,你也可以针对特定的资源来配置熔断规则。例如,你要对 /user/getUser 接口开启熔断功能,你可以添加如下配置:

    spring:
      cloud:
        sentinel:
          transport:
            port: 8719
            dashboard:
              enabled: false
        # 配置 `/user/getUser` 接口的熔断规则
          resources:
            - name: /user/getUser
              # 熔断开关是否打开
              enabled: true
              # 最大请求数(QPS)
              maxRequest: 10
              # 熔断超时时间(单位:毫秒)
              timeoutInMilliseconds: 1000
              # 熔断重试次数
              maxRetryTimes: 3
    

    启动你的 Spring Boot 项目。
    这样,Sentinel 就会对 /user/getUser 接口开启熔断功能。

    2023-09-13 14:53:23
    赞同 展开评论 打赏

为企业提供高效、稳定、易扩展的中间件产品。

相关电子书

更多
阿里云容器 AHAS Sentinel 网关流控揭秘 立即下载
workshop专场-微服务专场-开发者动手实践营-微服务-使用Sentinel进行微服务流量控制 立即下载
Sentinel分布式系统下的流量防卫兵 立即下载