I am using the latest Azure.Data.Tables
nuget package, version 12.3.0
to connect to Azure table storage in an ASP.NET Core C# Application.
My application needs to failover to a secondary region for reads if the primary region fails.
Currently the setup the of TableServiceClient
is done in the Startup.cs as follows:
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton(new TableServiceClient(new Uri("PrimaryRegionConnectionURL"), new DefaultAzureCredential()));
}
How do would I update the current instance of TableServiceClient
with an instance pointed to the secondary region? Is there a better approach to achieve this failover?
Just to Clarify:
I am aware that the client doesn't support failing over and the team have created a ticket to look at this feature in future.
I realize I need to have a new instance of TableServiceClient
.
I am just not sure how I would replace the one created at startup with a new instance pointed to the secondary instance at the time of failure.
Here is that code that consumes the TableServiceClient
public class TableRepository : ITableStorageRepository
{
readonly TableServiceClient _serviceClient;
public TableRepository(TableServiceClient serviceClient)
{
_serviceClient = serviceClient;
}
public async Task<ICollection<T>> GetPartitionEntities<T>(string partitionKey, string tableName)
where T : class, ITableEntity, new()
{
var listOfEntities = new List<T>();
var tableClient = _serviceClient.GetTableClient(tableName);
var queryResults = tableClient.QueryAsync<T>(filter => filter.PartitionKey == partitionKey);
await foreach (var row in queryResults)
{
listOfEntities.Add(row);
}
return listOfEntities;
}
}