polly

Polly Retry with RX Observable.Interval

喜欢而已 提交于 2019-12-11 15:09:55
问题 I'm new to Polly and I'm trying to apply the Retry policy, so that I can have it manually handling the retry connection in case of IBMMQ connection issue. Please, consider the following code: public class ReconnectException : Exception { } public class QueueMonitor : IObservable<Message>, IDisposable { private readonly MQQueue mqQueue; private readonly MQQueueManager queueManager; private readonly string queueName; private IDisposable timer; private readonly object lockObj = new object();

Polly policy to log exception and rethrow

泄露秘密 提交于 2019-12-07 06:24:15
问题 I consider to use Polly to create policy to log exception and rethrow. I didn't find an existing method that allow it out of the box , but some options that I see are Fallback // Specify a substitute value or func, calling an action (eg for logging) if the fallback is invoked. Policy.Handle<Whatever>() .Fallback<UserAvatar>(UserAvatar.Blank, onFallback: (exception, context) => { _logger.Log(exception, context); throw exception; }); Question: is it ok to throw exception from Fallback? Timeout

How to tell from Npgsql exception if the call is worth a retry (transient fault strategy)

ε祈祈猫儿з 提交于 2019-12-06 02:45:24
I'm writing a service which will be connecting to a remote postgres server. I'm looking for a good way to determine which exceptions should be treated as transient (worth retrying), and how to define an appropriate policy for connecting to a remote database. The service is using Npgsql for the data access. The documentation says that Npgsql will throw a PostgresException for sql errors and an NpgsqlException for "server related issues". So far the best I have been able to come up with is to assume all exceptions that are not PostgresExceptions should be treated as possibly transient, worth

Should Polly Policies be singletons?

烈酒焚心 提交于 2019-12-05 08:36:24
I have a query, IGetHamburgers , that calls an external API. I've registered the implementation of IGetHamburgers in my DI container as a Singleton. Im using Polly as a Circuitbreaker, if two requests fails the circuit will open. My goal is that all calls to the Hamburger api should go through the same circuitbreaker, if GetHamburgers fails, then all other calls should fail as well. How should I use my Policy? Should I register my Policy as a field like this: private Policy _policy; private Policy Policy { get { if(this_policy != null) { return this_policy; } this._policy = Policy .Handle

Polly policy to log exception and rethrow

落花浮王杯 提交于 2019-12-05 08:25:31
I consider to use Polly to create policy to log exception and rethrow. I didn't find an existing method that allow it out of the box , but some options that I see are Fallback // Specify a substitute value or func, calling an action (eg for logging) if the fallback is invoked. Policy.Handle<Whatever>() .Fallback<UserAvatar>(UserAvatar.Blank, onFallback: (exception, context) => { _logger.Log(exception, context); throw exception; }); Question: is it ok to throw exception from Fallback? Timeout Policy.Timeout(1, T30meoutStrategy.Pessimistic, (context, timespan, task) => { task.ContinueWith(t => {

Exception User-Unhandled reported in VS Debugger when using Polly

陌路散爱 提交于 2019-12-04 04:45:00
问题 I'm using Polly to catch an exception while calling a Pittney Bowes Geocoder service. I'm using a g1client library that throws a MessageProcessingException. I've wrapped the call in a Polly network policy to retry the call up to 3 times if this exception is thrown, but Visual Studio insists that the exception is "User-Unhandled" What do I need to modify to make this exception be handled? I'm using Visual Studio 2017 community Edition and C# 4.6.1. try { var networkPolicy = Policy .Handle

Check string content of response before retrying with Polly

帅比萌擦擦* 提交于 2019-12-03 20:25:45
问题 I'm working with a very flaky API. Sometimes I get 500 Server Error with Timeout , some other time I also get 500 Server Error because I gave it input that it can't handle SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM. . Both of these cases give me HttpRequestException but I can look into the reply message from the server and determine the cause of the exception. If it is a timeout error, I should try again. If it is a bad input I should re-throw the

Polly's Policy.TimeoutAsync does not work with PolicyWrap in an async context

人走茶凉 提交于 2019-12-02 04:49:22
问题 This is a FULLY working example (Copy/paste it and play around, just get the Polly Nuget) I have the following Console app code which makes a POST request to an HTTP client sandbox on 'http://ptsv2.com/t/v98pb-1521637251/post' (you can visit this link "http://ptsv2.com/t/v98pb-1521637251" to see the configuration or make yourself a "toilet"): class Program { private static readonly HttpClient _httpClient = new HttpClient() ; //WHY? BECAUSE - https://aspnetmonsters.com/2016/08/2016-08-27

Polly's Policy.TimeoutAsync does not work with PolicyWrap in an async context

老子叫甜甜 提交于 2019-12-02 01:04:47
This is a FULLY working example (Copy/paste it and play around, just get the Polly Nuget) I have the following Console app code which makes a POST request to an HTTP client sandbox on ' http://ptsv2.com/t/v98pb-1521637251/post ' (you can visit this link " http://ptsv2.com/t/v98pb-1521637251 " to see the configuration or make yourself a "toilet"): class Program { private static readonly HttpClient _httpClient = new HttpClient() ; //WHY? BECAUSE - https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/ static void Main(string[] args) { _httpClient.BaseAddress = new Uri(@"http://ptsv2.com

Understanding the semantics of Polly policies when separating policy definition from execution

放肆的年华 提交于 2019-12-01 09:27:48
With Polly I'd like to have my policy definition and the execution of that policy in two different statements, as in: // Policy definition var policy = Policy .HandleResult<IRestResponse>(predicate) .Retry(2); // Policy execution policy.ExecuteAndCapture(() => { DoSomethingAndReturnAnIRestResponse(); }; I want to do it this way so I can get better reuse of my retry policies, e.g. for use in dependency injection. I'm trying to understand if there's any considerations when splitting up the policy and the execution in this way, for example if there's any "state" (for lack of a better term) that