-
|
How can I register and use resiliency pipelines? And the code: var host = Host.CreateDefaultBuilder()
.ConfigureServices(services =>
{
services.AddBrighter(opt =>
{
var resiliencePipelineRegistry = new ResiliencePipelineRegistry<string>();
resiliencePipelineRegistry
.GetOrAddPipeline(
Constants.ImmediateRetry, // <-- seems to be removed from the pipelines avaiable to the command processor
builder => builder
.AddRetry(new RetryStrategyOptions{ MaxRetryAttempts = 10, Delay = TimeSpan.Zero}).Build());
resiliencePipelineRegistry
.GetOrAddPipeline(
CommandProcessor.OutboxProducer, // <-- A different exception is thown if no pipeline with this key is registered
builder => builder
.AddRetry(new RetryStrategyOptions{ MaxRetryAttempts = 1, Delay = TimeSpan.Zero}));
opt.ResiliencePipelineRegistry = resiliencePipelineRegistry;
})
.AutoFromAssemblies();
services.AddLogging(configure => configure.AddConsole());
})
.Build();
var commandBus = host.Services.GetRequiredService<IAmACommandProcessor>();
commandBus.Send(new GreetCommand($"Brighter{i}"));
static class Constants
{
public const string ImmediateRetry = "ImmediateRetry";
}
class GreetCommand(string name) : Command(Id.Random())
{
public string Name { get; init; } = name;
}
class GreetCommandHandler(ILogger<GreetCommandHandler> logger) : RequestHandler<GreetCommand>
{
[RequestLogging(step: 0, timing: HandlerTiming.Before)]
[UseResiliencePipeline(step: 1, policy: Constants.ImmediateRetry)] // <--- No exception is thrown if this line is removed
public override GreetCommand Handle(GreetCommand command)
{
Console.WriteLine($"Sync hello {name}");
}
}I am using version 10.0.1 public INeedMessaging Resilience(ResiliencePipelineRegistry<string> resiliencePipelineRegistry, IPolicyRegistry<string>? policyRegistry = null)
{
if (!resiliencePipelineRegistry.TryGetPipeline(CommandProcessor.OutboxProducer, out _))
{
throw new ConfigurationException("The resilience pipeline registry is missing the CommandProcessor.OutboxProducer resilience pipeline which is required");
}
policyRegistry ??= new DefaultPolicy();
#pragma warning disable CS0618 // Type or member is obsolete
if (!policyRegistry.ContainsKey(CommandProcessor.RETRYPOLICY))
{
throw new ConfigurationException("The policy registry is missing the CommandProcessor.RETRYPOLICY policy which is required");
}
if (!policyRegistry.ContainsKey(CommandProcessor.CIRCUITBREAKER))
{
throw new ConfigurationException("The policy registry is missing the CommandProcessor.CIRCUITBREAKER policy which is required");
}
#pragma warning restore CS0618 // Type or member is obsolete
_policyRegistry = policyRegistry;
return this;
}Any help is very much appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
I'll try to look at this weekend |
Beta Was this translation helpful? Give feedback.
I've created this bug issue: #3864