Expand description
Token-bucket rate limiter as a ServerInterceptor.
Provides RateLimitInterceptor, a ready-made interceptor that limits
request throughput per caller. The caller key is derived from
CallContext::caller_identity or the x-forwarded-for / peer IP header.
§Example
use std::sync::Arc;
use a2a_protocol_server::rate_limit::{RateLimitInterceptor, RateLimitConfig};
let limiter = Arc::new(RateLimitInterceptor::new(RateLimitConfig {
requests_per_window: 100,
window_secs: 60,
}));Then add it to the handler builder:
ⓘ
let handler = RequestHandlerBuilder::new(executor)
.with_interceptor(limiter)
.build()?;§Design
Uses a fixed-window counter per caller key. Windows are aligned to wall
clock seconds. When a request exceeds the per-window limit, the before
hook returns an error with code -32029 (“rate limit exceeded”).
For production deployments requiring sliding windows, distributed counters,
or more sophisticated algorithms, implement a custom ServerInterceptor
or use a reverse proxy (nginx, Envoy).
Structs§
- Rate
Limit Config - Configuration for
RateLimitInterceptor. - Rate
Limit Interceptor - A fixed-window rate limiting
ServerInterceptor.