TsgcWSCircuitBreaker › 属性 › PerEndpoint
基于模式的覆盖集合,对每个主机应用不同的 Thresholds/Recovery。
property PerEndpoint: TsgcCircuitBreakerEndpointList read FPerEndpoint
write SetPerEndpoint;
—
每个 TsgcCircuitBreakerEndpointItem 携带自己的 Pattern(支持通配符 * 和 ?)、OverrideThresholds 块和 OverrideRecovery 块。当活动密钥(通常是从出站 URL 派生的主机名)匹配某个已启用项时,该项的设置将在调用期间替换顶级的 Thresholds / Recovery,第一个匹配的已启用模式优先。子属性:Enabled(默认 False,为 False 时不评估任何项,仅使用顶级设置)和 Items(端点覆盖的 TCollection)。典型用法:为 api.openai.com 设置宽松阈值(因为它在负载下会变慢),同时为 api.stripe.com 设置快速打开(因为支付失败至关重要)。
sgcWSCircuitBreaker1.PerEndpoint.Enabled := True;
// OpenAI - lenient: 10 failures, 60s cooldown
with sgcWSCircuitBreaker1.PerEndpoint.Items.Add as TsgcCircuitBreakerEndpointItem do
begin
Pattern := 'api.openai.com';
OverrideThresholds.Enabled := True;
OverrideThresholds.FailureCount := 10;
OverrideRecovery.CooldownSec := 60;
end;
// Stripe - payment critical: open fast, recover slow
with sgcWSCircuitBreaker1.PerEndpoint.Items.Add as TsgcCircuitBreakerEndpointItem do
begin
Pattern := 'api.stripe.com';
OverrideThresholds.Enabled := True;
OverrideThresholds.FailureCount := 3;
OverrideRecovery.CooldownSec := 120;
end;