TsgcWSCircuitBreaker › 属性 › ServerKey
服务器端集成钩子(IsConnectionAllowed、IsMessageAllowed、RecordMessageError、RecordMessageSuccess)所使用的密钥。
property ServerKey: string read FServerKey write FServerKey;
—
当断路器用于保护 WebSocket / HTTP 服务器(自保护模式)时,服务器端辅助方法——IsConnectionAllowed、IsMessageAllowed、RecordMessageError、RecordMessageSuccess、RegisterConnection、UnregisterConnection——均将活动记录到由 ServerKey 标识的单个逻辑回路中。默认值为 'server'。当多个协作服务器共享同一个断路器实例,且您希望每个服务器在 Metrics 和 OnStateChange 事件中以各自的标签显示时,请更改此值。ServerKey 与 DefaultKey 相互独立:DefaultKey 适用于手动调用的 Execute / RecordSuccess / RecordFailure,通常用于命名出站依赖项;而 ServerKey 则用于命名服务器本身。
// Label the self-protection circuit with a human-readable name
sgcWSCircuitBreaker1.ServerKey := 'ws-server:8443';
// Server-side handlers route through ServerKey automatically
if not sgcWSCircuitBreaker1.IsConnectionAllowed(Connection.PeerIP) then
Connection.Disconnect;