TsgcWSCircuitBreakerMethods › IsMessageAllowed

IsMessageAllowed Method

Server-side gatekeeper that returns False when the ServerKey circuit is Open and rejects the message.

Syntax

function IsMessageAllowed(const aIP: string; const aMessage: string = ''): Boolean;

Parameters

NameTypeDescription
aIPconst stringPeer IP address of the sender. Accepted for logging and future per-IP metrics.
aMessageconst stringOptional message payload or identifier — accepted so future releases can apply content-based classification; ignored by the current evaluation.

Return Value

True when the ServerKey circuit is Closed or HalfOpen with a remaining trial, False when Open. Returns True unconditionally while Enabled is False. (Boolean)

Remarks

Server-side self-protection helper: delegates to IsCallAllowed(ServerKey). Call it from the server's OnMessage / BeforeMessage handlers and drop the message when it returns False so incoming traffic is shed while the server circuit is Open. Combine with RecordMessageSuccess / RecordMessageError so message-processing outcomes feed back into the breaker. This is a secondary server-integration hook — the primary use of the component is client-side protection of outbound HTTP API calls.

Example

procedure TForm1.WSServerMessage(Connection: TsgcWSConnection;
  const Text: string);
begin
  if not sgcWSCircuitBreaker1.IsMessageAllowed(Connection.PeerIP, Text) then
    Exit; // shed load while the server circuit is Open

  try
    HandleMessage(Text);
    sgcWSCircuitBreaker1.RecordMessageSuccess(Connection.PeerIP);
  except
    on E: Exception do
      sgcWSCircuitBreaker1.RecordMessageError(Connection.PeerIP, E.Message);
  end;
end;

Back to Methods