Spring Boot中的服务限制功能 [英] Service Throttling ability in Spring Boot
问题描述
有什么方法可以实现对Spring中其余服务的服务限制功能,尤其是在使用Spring Boot的情况下.
Is there any way to achieve the service throttling ability to the rest services in Spring, particular with Spring boot.
这里的期望是:我的服务暴露于外界,目前对每秒/分钟的服务呼叫数没有限制.我们想通过设置节流限制来控制这一点.
The Expectation here is: My services are exposed to outside world, currently there are no restrictions on the number of service calls per second/min. We want to control this by putting the throttling limit.
- 我还有一个选择,可以通过并发Hash Map或任何缓存机制跟踪请求.
但是对于考虑这一点的方式更感兴趣.我知道我可以在 node.js/scala
But more interested in the way spring in considering this. I know that i can be able to do it in node.js / scala
推荐答案
有一个相当新的开源项目可以处理此问题:
There is a fairly new opensource project which handles this:
https://github.com/weddini/spring-boot-throttling
对Spring服务进行节流控制的声明性方法. @Throttling注释可帮助您限制服务方法的数量 针对特定用户IP的每个java.util.concurrent.TimeUnit调用 地址,HTTP标头/cookie值或使用Spring Expression Language (SpEL).
Declarative approach of throttling control over the Spring services. @Throttling annotation helps you to limit the number of service method calls per java.util.concurrent.TimeUnit for a particular user, IP address, HTTP header/cookie value, or using Spring Expression Language (SpEL).
这篇关于Spring Boot中的服务限制功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!