Overview
The@RateLimit annotation declares a rate limit policy for a method or type. It carries configuration metadata that is read by the enforcement layer (aspect/interceptor) to apply rate limiting.
Package: io.github.v4runsharma.ratelimiter.annotation
Source: RateLimit.java:22
Annotation targets
ElementType.METHOD- Apply to individual methodsElementType.TYPE- Apply to entire classes (inherited by all methods)
Parameters
Optional logical name for the limit. Used for metrics tags, configuration override lookup, or documentation.
Optional scope hint for the policy (e.g., “user”, “ip”, “global”). How this is interpreted depends on the policy provider and key resolver strategy.
Maximum number of allowed requests within the time window. Must be greater than 0.
Window size in the specified time unit. Must be positive.
Time unit for the duration parameter. Defaults to
SECONDS.Key resolver type to compute the rate limit key for this annotation. Defaulting to the interface type acts as a sentinel meaning “not explicitly set”; the starter substitutes a default implementation.
Optional static key suffix to disambiguate limits without writing a custom resolver.
Feature flag to disable enforcement without removing the annotation.
Usage examples
Basic rate limit
Limit a method to 10 requests per second:User-scoped rate limit
Limit per user to 100 requests per minute:IP-based rate limit
Limit per IP address to 1000 requests per hour:Custom key
Use a static key suffix:Class-level rate limit
Apply to all methods in a class:Disabled rate limit
Temporarily disable without removing the annotation:Related
- RateLimitKeyResolver - Customize key resolution
- RateLimitPolicy - Policy model created from annotation
- RateLimitScope - Available scope values