TsgcWSCircuitBreakerMethods › RecordMessageError

RecordMessageError Method

Server-side hook that records a message failure on ServerKey.

Syntax

procedure RecordMessageError(const aIP: string; const aException: string = '');

Parameters

NameTypeDescription
aIPconst stringPeer IP address of the connection that delivered the failing message. Accepted for logging and future per-IP metrics.
aExceptionconst stringOptional exception text (ClassName: Message) passed to Classification so server-side business errors can be ignored.

Remarks

WebSocket-message flavored failure recorder for server-side self-protection. Delegates to RecordFailure(ServerKey, aException) — the IP parameter is currently informational. Call from the server's OnMessage handler when processing fails so the breaker can trip itself Open if the server is overwhelmed (for example by a burst of malformed messages or a dependent downstream that has fallen over). OnFailureRecorded fires with ServerKey as the key. Returns immediately when Enabled is False.

Example

procedure TForm1.WSServerMessage(Connection: TsgcWSConnection;
  const Text: string);
begin
  try
    HandleMessage(Text);
    sgcWSCircuitBreaker1.RecordMessageSuccess(Connection.PeerIP);
  except
    on E: Exception do
    begin
      sgcWSCircuitBreaker1.RecordMessageError(Connection.PeerIP,
        Format('%s: %s', [E.ClassName, E.Message]));
      raise;
    end;
  end;
end;

Back to Methods