How to Limit Execution Rate
This is an additional feature of SmallRye Fault Tolerance and is not specified by MicroProfile Fault Tolerance. |
It is possible to prevent an operation from being executed too often using a rate limit.
@RateLimit
The @RateLimit
annotation specifies that a rate limit should be enforced for all method calls.
@ApplicationScoped
public class MyService {
@RateLimit (1)
public String hello() {
...
}
}
1 | Declares that hello() must not be called too often.
Since there is no configuration, the default is at most 100 calls per 1 minute. |
If the method is called too often, excess attempts will fail with RateLimitException
.
It is possible to specify the maximum allowed rate of execution (the rate limit), together with minimum spacing between invocations. There are also several types of rate limiting to choose from.
Links
For more information, see the Rate Limit reference guide.