美文网首页
微服务流量整形-sentinel的简单使用

微服务流量整形-sentinel的简单使用

作者: 侧耳倾听y | 来源:发表于2022-01-21 16:20 被阅读0次

1. 从github下载sentinel

https://github.com/alibaba/Sentinel/releases

可以下载1.8.2版本

2. 启动 sentinel

java -Dserver.port=8080 -Dcsp.sentinel.dashboard.server=localhost:8080  -jar sentinel-dashboard-1.8.2.jar

浏览器输入:http://localhost:8080,用户名和密码都是sentinel

3. 将服务接入到 sentinel控制台

  • 添加依赖
<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
  • 添加配置
spring:
  cloud:
    sentinel:
      transport:
        # sentinel api端口,默认8719
        port: 8719
        # dashboard地址
        dashboard: localhost:8080
  • 对资源进行标记

在 Sentinel 的世界中,万物都是可以被保护的“资源”。

@GetMapping("/get")
@SentinelResource(value = "get")
public TestObj get(@RequestParam("id") Long id){
}
  1. 设置流控规则

登录 Sentinel 控制台之后,在左侧的导航栏是看不到刚注册的微服务的。这时发起几个调用,触发服务信息的上报,再等上个几秒钟,即可在 Sentinel 里看到微服务。


  1. 设置异常降级配置

相关文章

网友评论

      本文标题:微服务流量整形-sentinel的简单使用

      本文链接:https://www.haomeiwen.com/subject/vdwehrtx.html