Much of the work in this project is derived from Microsoft's Enterrpise Library Transient Fault Handling Block and Microsoft's RestClientRuntime.
You can execute a command using the ReliableSqlConnection
class...
using(var cn = new ReliableSqlConnection(connectionString))
{
using(var cmd = new SqlCommand(sql))
{
cn.Open();
using(var rdr = cn.ExecuteCommand<IDataReader>(cmd))
{
...
}
}
}
...or you can use the OpenWithRetry()
and ExecuteXxxxWithRetry()
extension methods, and pass a specific RetryPolicy
...
using(var cn = new SqlConnection(connectionString))
{
using(var cmd = new SqlCommand(sql, cn))
{
cn.OpenWithRetry(connectionRetryPolicy);
using(var rdr = cmd.ExecuteReaderWithRetry(commandRetrypolicy)}
{
...
}
}
}
Using the extension methods allows you to taylor retry policies specific to a particular command.
var retryHandler = new RetryDelegatingHandler { InnerHandler = new HttpClientHandler() };
var httpClient = new HttpClient(retryHandler);
Be careful when using retries on operations that change state--ie. database INSERT, UPDATE, DELETE and Http POST, PUT, DELETE. Ensure that the operation is idempotent--the operation will yield the same result regardless of how many times it is performed. Severed connections, espectially in HTTP, can result in the request still completing. Most databases, will rollback a transaction automatically if a connection is broken prior to commit.
EF6 and EF Core, provide transient retry out of the box with the SQL Server, Pomelo.EntityFrameworkCore.MySql, Npgsql.EntityFrameworkCore.PostgreSQL, and DevArt providers. MilestoneTG.TransientFaultHandling.Data.* is not needed in these scenarios.
Contains RetryDelegatingHandler
and supporting constructs that adds transient retry capability to the HttpClient
pipeline.
HttpClientBuilder extensions to support HttpClientFactory.
Supports transient fault handling for Microsoft SQL Server, including cloud provided solutions such as Azure SQL Database, AWS RDS for SQL Server.
NHiberate provider for Microsoft SQL Server that leverages reliable connections and commands.
Supports transient fault handling for most implementations of MySQL including MySQL, MariaDB, Percona MySQL, Azure Database for MySQL, AWS Aurora MySQL (including Aurora Serverless) and, AWS RDS for MySQL.
Supports transient fault handling for most implementations of PostreSQL including PostgreSQL, EnterpriseDB, Percona PostgreSQL, Azure Database for PostgreSQL, AWS Aurora PostgreSQL, AWS RDS for PostgreSQL, and AWS Red Shift.
Supports transient fault handling for most deployments of Oracle including on premises, Azure, AWS RDS, and Oracle Cloud.
If you wish to contribute to this project, please open an issue first to discuss the desired change/contribution.
For bugs, questions and discussions please use the GitHub Issues.