how to implement custom method when Polly circuit is close

故事扮演 提交于 2019-12-11 17:40:02

问题


I have method which returns IAsyncPolicy<HttpResponseMessage> and it has 2 or more policies along with CircuitBreaker and part of my DI.

Now in my implementation class I added one extra fallbackPolicy to handle BrokenCircuitException and wrap it with IAsyncPolicy<HttpResponseMessage> (AsyncPolicy)

Now I did my custom method implementation within DoWork() method, Great!!! Thanks to FallbackAsync policy where I'm catching BrokenCircuitException exception, means when circuit is open.

var fallbackPolicy = Policy<HttpResponseMessage>
                .Handle<BrokenCircuitException>()
                .FallbackAsync(async (cancellationToken) => await DoWork()
                .ConfigureAwait(false));

            var policyWrap = fallbackPolicy.WrapAsync(AsyncPolicy);

            // Send message to service
            var response = await policyWrap.ExecuteAsync(() => HttpClient.PostAsync(...

Now question is, do we have any policy or a way to know when the circuit is close and I can write my own method implementation?

In my shared policy where I have CircuitBreaker` too which I wrote as in DI area have below signature, but I can't write my custom method implementation here.

onReset: () =>
                    {
                        Trace.TraceInformation("Web API Close");
                    },

来源:https://stackoverflow.com/questions/58928939/how-to-implement-custom-method-when-polly-circuit-is-close

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!