add 增加 集群限流演示案例

This commit is contained in:
疯狂的狮子li 2021-09-17 17:22:55 +08:00
parent dcaeb18870
commit 2569e8c0a4
1 changed files with 26 additions and 2 deletions

View File

@ -2,6 +2,7 @@ package com.ruoyi.demo.controller;
import com.ruoyi.common.annotation.RateLimiter;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.LimitType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
@ -22,13 +23,36 @@ import org.springframework.web.bind.annotation.RestController;
public class RedisRateLimiterController {
/**
* 测试限流注解
* 测试全局限流
* 全局影响
*/
@ApiOperation("测试限流注解")
@ApiOperation("测试全局限流")
@RateLimiter(count = 2, time = 10)
@GetMapping("/test")
public AjaxResult<String> test(String value){
return AjaxResult.success("操作成功",value);
}
/**
* 测试请求IP限流
* 同一IP请求受影响
*/
@ApiOperation("测试请求IP限流")
@RateLimiter(count = 2, time = 10, limitType = LimitType.IP)
@GetMapping("/testip")
public AjaxResult<String> testip(String value){
return AjaxResult.success("操作成功",value);
}
/**
* 测试集群实例限流
* 启动两个后端服务互不影响
*/
@ApiOperation("测试集群实例限流")
@RateLimiter(count = 2, time = 10, limitType = LimitType.CLUSTER)
@GetMapping("/testcluster")
public AjaxResult<String> testcluster(String value){
return AjaxResult.success("操作成功",value);
}
}