Class RateLimit


public class RateLimit extends ObjectWithJsonToString
Declarative, protocol-agnostic rate-limiting / quota action attached to an Expectation (a sibling of chaos). When a matched expectation carries a rateLimit clause and the request is over-limit for the current window, a deterministic errorStatus (default 429) response is returned instead of the normal response, carrying Retry-After and X-RateLimit-* headers; when the request is within the limit the normal response is returned unchanged.

Counting is backed by a shared, named in-process registry (RateLimitRegistry): expectations that share a name share one counter (model an upstream account limit); when name is null the expectation's own id is used as the counter key so a single expectation rate-limits in isolation. v1 supports two algorithms:

  • FIXED_WINDOW — at most limit requests per windowMillis; the window starts on the first request and resets once it elapses.
  • TOKEN_BUCKET — a bucket of capacity burst refilling at refillPerSecond tokens/second; a request is allowed when at least one token is available (and consumes it).
v1 is node-local. Follows the model field/withX/getter convention so it round-trips without a bespoke (de)serializer.