Skip to content

Conversation

@MikkelSchmidtDFDS
Copy link

Added possibility to inject an IConsumerExecutionStrategy per Consumer.

This is to enable events for a Consumer to be processed in a custom strategy.
This custom execution strategy can for instance be utilized to implement some custom resiliency mechanism.

A setup example:

public void ConfigureServices(IServiceCollection services)
{
    services.AddConsumer(options =>
    {
        options.WithConsumerExecutionStrategyFactory(sp =>
        {
            return new ResilienceExecutionStrategy(
                "some-pipeline-name", 
                sp.GetRequiredService<ResiliencePipelineProvider<string>>());
        });
    });
}

@DFDS-Snyk
Copy link

DFDS-Snyk commented Dec 5, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

Copy link
Collaborator

@toizo toizo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

I'm not 100% fond of how the ConsumerOptions just passes a factory down to the builder. It would be nice if this can be consistent with how UnconfiguredMessageHandlingStrategy is configured.

Other than that, the rest is only about naming things - see my comments.

@MikkelSchmidtDFDS
Copy link
Author

Nice!

I'm not 100% fond of how the ConsumerOptions just passes a factory down to the builder. It would be nice if this can be consistent with how UnconfiguredMessageHandlingStrategy is configured.

Other than that, the rest is only about naming things - see my comments.

Thanks!

As also commented on your other comment, I have made it consistent with the other factories to make sure it is possible to register a different execution strategy per consumer :) Please let me know if you still think there is a better way to do it.

I have tried to update according to you other great comments, but let me know if there is still something that can improve.

I found one issue thatI forgot to commit before the vacation. So I have included it now: the Cancellation token is now passed through the execution strategy and I have included a MessageExecutionContext in the IMessageHandlerExecutionStrategy, so the strategy can be aware of the message it is processing.

… to include a MessageExecutionContext and CancellationToken
@MikkelSchmidtDFDS MikkelSchmidtDFDS force-pushed the allow-injection-of-consumer-execution-strategy branch from 9db9574 to 54b22d5 Compare January 9, 2026 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants