Table of Contents

Class PollyTransportCircuitBreakerRegistry

Namespace
Excalibur.Dispatch.Resilience.Polly
Assembly
Excalibur.Dispatch.Resilience.Polly.dll

Polly-based implementation of ITransportCircuitBreakerRegistry that manages per-transport circuit breakers using Polly's resilience pipeline.

public sealed class PollyTransportCircuitBreakerRegistry : ITransportCircuitBreakerRegistry, ITransportCircuitBreakerDiagnostics, IDisposable
Inheritance
PollyTransportCircuitBreakerRegistry
Implements
Inherited Members
Extension Methods

Remarks

This registry creates and manages PollyCircuitBreakerPolicyAdapter instances for each transport, ensuring transport-level isolation of failures. When one transport experiences issues, other transports continue operating normally.

The registry is thread-safe and lazily creates circuit breakers on first access.

Constructors

PollyTransportCircuitBreakerRegistry()

Initializes a new instance of the PollyTransportCircuitBreakerRegistry class with default options.

public PollyTransportCircuitBreakerRegistry()

PollyTransportCircuitBreakerRegistry(CircuitBreakerOptions, ILogger<PollyTransportCircuitBreakerRegistry>?)

Initializes a new instance of the PollyTransportCircuitBreakerRegistry class.

public PollyTransportCircuitBreakerRegistry(CircuitBreakerOptions defaultOptions, ILogger<PollyTransportCircuitBreakerRegistry>? logger)

Parameters

defaultOptions CircuitBreakerOptions

The default circuit breaker options for new registrations.

logger ILogger<PollyTransportCircuitBreakerRegistry>

Optional logger instance.

PollyTransportCircuitBreakerRegistry(IOptions<CircuitBreakerOptions>, ILogger<PollyTransportCircuitBreakerRegistry>?)

Initializes a new instance of the PollyTransportCircuitBreakerRegistry class using options from dependency injection.

public PollyTransportCircuitBreakerRegistry(IOptions<CircuitBreakerOptions> options, ILogger<PollyTransportCircuitBreakerRegistry>? logger = null)

Parameters

options IOptions<CircuitBreakerOptions>

The circuit breaker options accessor.

logger ILogger<PollyTransportCircuitBreakerRegistry>

Optional logger instance.

Properties

Count

Gets the number of registered circuit breakers.

public int Count { get; }

Property Value

int

Methods

Dispose()

Disposes all managed circuit breakers and clears the registry.

public void Dispose()

GetAllStates()

Gets the current states of all registered circuit breakers.

public IReadOnlyDictionary<string, CircuitState> GetAllStates()

Returns

IReadOnlyDictionary<string, CircuitState>

A dictionary mapping transport names to their circuit states.

GetOrCreate(string)

Gets or creates a circuit breaker for the specified transport using default options.

public ICircuitBreakerPolicy GetOrCreate(string transportName)

Parameters

transportName string

The name of the transport (e.g., "RabbitMQ", "AzureServiceBus").

Returns

ICircuitBreakerPolicy

The circuit breaker policy for the transport.

Exceptions

ArgumentNullException

transportName is null.

ArgumentException

transportName is empty or consists only of white-space characters.

GetOrCreate(string, CircuitBreakerOptions)

Gets or creates a circuit breaker for the specified transport with custom options.

public ICircuitBreakerPolicy GetOrCreate(string transportName, CircuitBreakerOptions options)

Parameters

transportName string

The name of the transport.

options CircuitBreakerOptions

The circuit breaker configuration options.

Returns

ICircuitBreakerPolicy

The circuit breaker policy for the transport.

Exceptions

ArgumentNullException

transportName or options is null.

ArgumentException

transportName is empty or consists only of white-space characters.

GetTransportNames()

Gets the names of all registered transports.

public IEnumerable<string> GetTransportNames()

Returns

IEnumerable<string>

A collection of transport names.

Remove(string)

Removes a circuit breaker for the specified transport.

public bool Remove(string transportName)

Parameters

transportName string

The name of the transport.

Returns

bool

True if the circuit breaker was removed; otherwise, false.

Exceptions

ArgumentNullException

transportName is null.

ArgumentException

transportName is empty or consists only of white-space characters.

ResetAllAsync(CancellationToken)

Returns every registered circuit breaker to the closed state.

public Task ResetAllAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Cancellation token.

Returns

Task

A task that completes once every circuit is closed.

Remarks

When the returned task completes, every circuit this registry holds reports Closed. The individual resets are awaited rather than started, so a caller that needs the whole registry back in service can wait for exactly that.

TryGet(string)

Tries to get an existing circuit breaker for the specified transport.

public ICircuitBreakerPolicy? TryGet(string transportName)

Parameters

transportName string

The name of the transport.

Returns

ICircuitBreakerPolicy

The circuit breaker policy if found; otherwise, null.

Exceptions

ArgumentNullException

transportName is null.

ArgumentException

transportName is empty or consists only of white-space characters.