Skip to content

[Feature]: Resilience Pipeline Behavior (Polly Integration) #219

@eneshoxha

Description

@eneshoxha

Title: Add resilience pipeline behaviors with Polly v8 / Microsoft.Extensions.Resilience integration

Labels: enhancement, mediator, new-package

Body:

Problem

There are no built-in retry, circuit-breaker, or timeout pipeline behaviors. In event-driven architectures (especially with Cortex.Streams and Kafka), transient failures are common and handlers that call external services need resilience patterns.

Proposed Solution

Create a Cortex.Mediator.Behaviors.Resilience package:

  • ResilienceCommandBehavior<TCommand, TResult> -- wraps command execution with a Polly ResiliencePipeline
  • ResilienceQueryBehavior<TQuery, TResult> -- same for queries
  • Support per-handler resilience via IResilientRequest interface or [Resilient] attribute
  • Global default resilience pipeline via options
services.AddMediatorResilience(options =>
{
    options.DefaultPipeline = new ResiliencePipelineBuilder()
        .AddRetry(new RetryStrategyOptions { MaxRetryAttempts = 3 })
        .AddTimeout(TimeSpan.FromSeconds(10))
        .Build();
});

Dependencies

  • Microsoft.Extensions.Resilience (which wraps Polly v8)

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestfeatureThis label is in use for minor version increments

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions