对API进行费率限制(春季MVC) [英] Rate-Limit an API (spring MVC)

查看:121
本文介绍了对API进行费率限制(春季MVC)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找实现(或使用已经设置好的)限速器的最佳方法,该限速器将保护我所有的剩余api网址.我正在查看的保护是每个用户限制器每秒的通话次数"

I'm looking the best more efficient way to implement (or use an already setup) rate limiter that would protect all my rest api url. the protection I'm looking at is a "call per second per user limiter"

我在网上看了一下,结果发现是使用了"Redis"或Guava RateLimiter.

I had a look on the net and what comes out was the use of either "Redis" or Guava RateLimiter.

说实话,我从未使用过Redis,而且我真的不熟悉它.但是通过查看其文档,看来它具有相当强大的速率限制器系统.

To be honest I have never used Redis and I'am really not familiar with it. But by looking on its docs it seems that it has a quite robust rate limiter system.

我也看了番石榴的RateLimiter.而且它看起来更易于使用(不需要安装Redis等)

I have also had a look at Guava's RateLimiter. And it looks a bit easier to use (don't need a redis installation etc...)

因此,我想提出一些就我而言"最佳解决方案的建议?使用Redis太多了吗?

So I would like some suggestion of what would be "in my case" the best solution? Is using Redis "too much"?

你们中的任何人已经尝试过RateLimter吗?这是一个好的解决方案吗?可伸缩吗?

Have any of you already tried RateLimter? Is this a good solution? Is it scaleable?

PS:如果您认为有更好的选择,那么我也愿意接受其他2种解决方案.

PS: I am also open to other solutions than the 2 I aforementioned if you think there are better choices.

谢谢!

推荐答案

如果您试图限制对基于Spring的REST api的访问,则应使用

If you are trying to limit access to your Spring-based REST api you should use token-bucket algorithm.

有一个 bucket4j-spring-boot-starter 项目,该项目使用 bucket4j 库以限制对REST api的访问.您可以通过应用程序属性文件进行配置.可以选择根据IP地址或用户名限制访问权限

There is bucket4j-spring-boot-starter project which uses bucket4j library to rate-limit access to the REST api. You can configure it via application properties file. There is an option to limit the access based on IP address or username.

如果您使用的是 Netflix Zuul ,则可以使用

If you are using Netflix Zuul you could use Spring Cloud Zuul RateLimit which uses different storage options: Consul, Redis, Spring Data and Bucket4j.

这篇关于对API进行费率限制(春季MVC)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆