Polly 🕊
Polly is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback in a fluent and thread-safe manner. ♻️
Installing via NuGet 🗃 :
Usage :
We retry to send the email 3 times if something failed ❌ :
🔹🔸🔹🔸
https://t.me/pgimg/79
[ Github ] : http://bit.do/pollyc
〰〰〰〰〰〰
#CSharp #RetryPattern
@ProgrammingTip
Polly is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback in a fluent and thread-safe manner. ♻️
Installing via NuGet 🗃 :
Install-Package Polly
Usage :
public class Mailer
{
public static bool SendEmail()
{
Console.WriteLine("Sending Mail ...");
// simulate error
Random rnd = new Random();
var rndNumber = rnd.Next(1, 10);
if (rndNumber != 3)
throw new SmtpFailedRecipientException();
Console.WriteLine("Mail Sent successfully");
return true;
}
}
We retry to send the email 3 times if something failed ❌ :
var policy = Policy.Handle<SmtpFailedRecipientException>().Retry(3);
policy.Execute(Mailer.SendEmail);
🔹🔸🔹🔸
https://t.me/pgimg/79
[ Github ] : http://bit.do/pollyc
〰〰〰〰〰〰
#CSharp #RetryPattern
@ProgrammingTip
Telegram
Programming Tips Resources