RateLimitConfigurer class abstract
Defines the programmatic configuration entry point for the rate-limiting subsystem.
The RateLimitConfigurer interface allows developers and framework integrators to register and customize various components related to rate limiting—such as storages, managers, resolvers, and error handlers—during the application initialization or container bootstrap phase.
Purpose
Implementations of this interface act as extension hooks for configuring the rate-limiting infrastructure dynamically, complementing declarative configuration through annotations like RateLimit.
It enables flexible integration with external systems (e.g., Redis, databases, distributed caches) and supports environment-based conditional registration.
Lifecycle
- The framework automatically detects and executes all RateLimitConfigurer implementations during the startup process.
- The order of execution may depend on whether the configurer implements
ordering interfaces such as
OrderedorPriorityOrdered. - Each configuration method receives the relevant registry, allowing modular registration of components.
Responsibilities
- Registering one or more RateLimitManager instances that coordinate storage backends.
- Adding RateLimitStorage implementations to handle rate tracking logic.
- Registering RateLimitResolvers that determine which storage(s) a given RateLimit annotation should use.
Example
class MyRateLimitConfigurer extends RateLimitConfigurer, PriorityOrdered {
@override
void configureRateLimitManager(RateLimitManagerRegistry registry) {
registry.addManager(DefaultRateLimitManager('primary'));
}
@override
void configureRateLimitStorage(RateLimitStorageRegistry registry) {
registry.addStorage(InMemoryRateLimitStorage('local'));
registry.addStorage(RedisRateLimitStorage('redis-main'));
}
@override
void configureRateLimitResolver(RateLimitResolverRegistry registry) {
registry.addResolver(DefaultRateLimitResolver());
}
@override
int getOrder() => Ordered.HIGHEST_PRECEDENCE;
}
In this example:
- A default manager and two storage backends are registered.
- A resolver is added to determine which storage should handle each operation.
- The configurer declares high precedence to ensure it runs before others.
Related Components
- RateLimitManagerRegistry — Registry for rate limit managers.
- RateLimitStorageRegistry — Registry for rate limit storage implementations.
- RateLimitResolverRegistry — Registry for resolver components.
- RateLimitManager — Central orchestrator for rate limit storage.
- RateLimitResolver — Responsible for resolving which storage(s) to use.
RateLimitErrorHandler— Optional component for handling runtime exceptions.
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
configure(
String name, ConfigurableRateLimitStorage storage) → void - Configures a ConfigurableRateLimitStorage instance conditionally by name.
-
configureRateLimitManager(
RateLimitManagerRegistry registry) → void - Configures and registers one or more RateLimitManager instances.
-
configureRateLimitResolver(
RateLimitResolverRegistry registry) → void - Configures and registers RateLimitResolver implementations.
-
configureRateLimitStorage(
RateLimitStorageRegistry registry) → void - Configures and registers RateLimitStorage implementations.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited