Replies: 2 comments
-
@lonix1 Hi, do you already have this knowledge? I need this solution also. |
Beta Was this translation helpful? Give feedback.
-
I think there is some misunderstanding so, let me try to clarify. Registry and PipelineSo, whenever you register a pipeline inside a registry then you can't dispose the pipeline directly. (The Polly/test/Polly.Core.Tests/Registry/ResiliencePipelineRegistryTests.cs Lines 439 to 446 in 4f0d44a You can only dispose the pipeline through the registry: Polly/test/Polly.Core.Tests/Registry/ResiliencePipelineRegistryTests.cs Lines 410 to 436 in 4f0d44a Disposed PipelineAfter the registry has been disposed you obviously can't retrieve a pipeline because you will get an Let's suppose you have retrieved a pipeline just before the registry disposal. If you want to invoke a method on the pipeline like the Retrieving a strategy from a pipeline can be achieved via var registry = new ResiliencePipelineRegistry<string>();
registry.TryAddBuilder("A", (builder, _) =>
{
builder.AddRateLimiter(new SlidingWindowRateLimiter(
new SlidingWindowRateLimiterOptions
{
PermitLimit = 10,
Window = TimeSpan.FromMinutes(1),
SegmentsPerWindow = 1
}));
});
var pipeline = registry.GetPipeline("A");
registry.Dispose();
try
{
pipeline.Execute(() => {});
}
catch(ObjectDisposedException)
{
Console.WriteLine("Pipeline has been disposed");
}
var strategy = pipeline.GetPipelineDescriptor().FirstStrategy.StrategyInstance;
var executeCore = typeof(ResilienceStrategy).GetMethod("ExecuteCore", BindingFlags.Instance | BindingFlags.NonPublic);
executeCore = executeCore.MakeGenericMethod(new[] {typeof(object), typeof(object)});
var context = ResilienceContextPool.Shared.Get();
Func<ResilienceContext, object, ValueTask<Outcome<object>>> callback = (_, __) => Outcome.FromResultAsValueTask<object>("Test");
var executeTask = (ValueTask<Outcome<object>>)executeCore.Invoke(strategy, parameters: [callback, context, null]);
var executeOutcome = await executeTask;
ResilienceContextPool.Shared.Return(context);
Console.WriteLine(executeOutcome.Result); It will print
So, as you can see the pipeline is disposed but the strategy isn't. |
Beta Was this translation helpful? Give feedback.
-
One benefit of the "resilience registry" is that it is easy to dispose:
Does that also include chained rate limiters?
Suppose I have a pipeline with multiple limiters (e.g. concurrency limiter and rate limiter) and also a chained rate limiter which itself contains rate limiters - are all of those disposed when the registry is disposed?
Beta Was this translation helpful? Give feedback.
All reactions