Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

怎么对整个OpenFeign的客户端接口进行QPS总量限流 #3471

Open
xiaopang-8 opened this issue Nov 6, 2024 · 2 comments
Open

怎么对整个OpenFeign的客户端接口进行QPS总量限流 #3471

xiaopang-8 opened this issue Nov 6, 2024 · 2 comments

Comments

@xiaopang-8
Copy link

现在有这样一个需求, 我在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
  }
]
@qingmo
Copy link

qingmo commented Nov 20, 2024

注意使用dashboard对接看下自动生成的resourceName是什么,不是hystrix那套了,所以你这个配置根本不会生效

@LearningGp
Copy link
Collaborator

我比较好奇这个场景,按我的理解这种限流应该配置在B服务上,因为如果在客户端进行限制,A服务或者B服务扩容时都存在问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants