TsgcWSRateLimiterEvents › OnThrottled

OnThrottled Event

Fired when a request is rejected by the strategy or burst protection.

Syntax

property OnThrottled: TsgcRateLimitOnThrottled;
// TsgcRateLimitOnThrottled = procedure(Sender: TObject; const aKey, aReason: string; var Allow: Boolean) of object

Default Value

Remarks

Fired from inside Consume / IsAllowed every time a request is rejected, and also from IsConnectionAllowed / IsMessageAllowed. The aKey parameter is the rate-limit key that was evaluated (an IP, apikey:XXX or user:...) and aReason is one of "token_bucket", "sliding_window", "fixed_window", "burst", "connection_rate" or "message_rate". The Allow parameter is a var Boolean that starts as False and the handler can set to True to override the decision and let the request through anyway — useful for trusted clients, for VIP allow-lists or to escalate tier limits dynamically. Runs synchronously on the thread that invoked the allowance check; keep the handler fast.

Example

procedure TForm1.RateLimiterThrottled(Sender: TObject;
  const aKey, aReason: string; var Allow: Boolean);
begin
  Log('Throttled ' + aKey + ': ' + aReason);
  // VIP override: trusted internal IP always allowed
  if aKey = '10.0.0.1' then
    Allow := True;
end;

Back to Events