Sentinel 限流

一、安装客户端:1.6.0版本

1、下载地址 sentinel-dashboard-1.6.0.jar

2、 启动

java -Dserver.port=8888 -Dsentinel.dashboard.auth.username=sentinel -Dsentinel.dashboard.auth.password=123456 -Dserver.servlet.session.timeout=7200 -jar sentinel-dashboard-1.6.0.jar
  • -Dsentinel.dashboard.auth.username=sentinel:登录用户名
  • -Dsentinel.dashboard.auth.password=123456:登录密码
  • -Dserver.servlet.session.timeout=7200:Spring Boot 服务端 session 的过期时间,单位秒,默认30分钟

 3、访问地址:http://localhost:8888

 

二、安装Sentinel到项目

1、pom

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.2</version>
        <optional>true</optional>
    </dependency>
</dependencies>

2、yml

server:
  port: 9010

spring:
  application:
    name: spring-cloud-cfl-sentinel
  cloud:
    sentinel:
      transport:
        dashboard: 127.0.0.1:8888    # 上面安装sentinel dashboard的访问地址

3、创建Controller

@RestController
@RequestMapping("/test/")
public class TestController {

    @RequestMapping("test2")
    public String test2() {
        return "hello sentinel2";
    }
}

4、访问:http://localhost:9010/test/test2

三、配置限流规则

1、点击簇点链路 -> 流控

 3、频繁访问接口:http://localhost:9010/test/test2

  •  可以看到最大通过的QPS就是上面做设置的2,有被拒绝的QPS
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值