Sentinel
Sentinel copied to clipboard
怎么对整个OpenFeign的客户端接口进行QPS总量限流
现在有这样一个需求, 我在A服务中调用B服务, 但是B服务要求每秒总请求不能超过60QPS, 例如,如下Feign客户端, 我应该怎么写才能实现对类中所有方法的总QPS进行限制 还有一种按分钟的, 每分钟不能超过2000QPS应该怎么实现
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
/**
* 用户服务
*
*/
@FeignClient(contextId = "remoteUserService", value = "ruoyi-system")
public interface RemoteUserService
{
@GetMapping(value = "/user/info/{username}")
public Object getUserInfo(@PathVariable("username") String username);
/**
* 通过用户名查询用户信息
*
* @param username 用户名
* @return 结果
*/
@GetMapping(value = "/user/info/{userId}")
public Object getUserInfo(@PathVariable("userId") Long userId);
}
我尝试在接口上添加 @SentinelResource("remoteUserService") 然后再nacos中配置, 不起作用
[
{
"resource": "remoteUserService",
"count": 1,
"grade": 1,
"limitApp": "default",
"strategy": 0,
"controlBehavior": 0,
"maxQueueingTimeMs": 2000
}
]
注意使用dashboard对接看下自动生成的resourceName是什么,不是hystrix那套了,所以你这个配置根本不会生效
我比较好奇这个场景,按我的理解这种限流应该配置在B服务上,因为如果在客户端进行限制,A服务或者B服务扩容时都存在问题