【发布时间】:2022-01-18 17:33:54
【问题描述】:
我正在使用最新的 Azure.Data.Tables nuget 包,版本 12.3.0 连接到 ASP.NET Core C# 应用程序中的 Azure 表存储。
如果主要区域发生故障,我的应用程序需要故障转移到次要区域以进行读取。
目前TableServiceClient的设置是在Startup.cs中完成的,如下:
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton(new TableServiceClient(new Uri("PrimaryRegionConnectionURL"), new DefaultAzureCredential()));
}
如何使用指向次要区域的实例更新TableServiceClient 的当前实例?有没有更好的方法来实现这种故障转移?
只是为了澄清:
我知道客户端不支持故障转移,并且团队已经创建了一张票以在将来查看此功能。
我意识到我需要一个 TableServiceClient 的新实例。
我只是不确定在失败时如何用指向辅助实例的新实例替换启动时创建的实例。
这是使用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;
}
}
【问题讨论】:
-
您使用的 SDK 是什么?
-
@GauravMantri 我正在使用一个 nuget 包
Azure.Data.Tables,它是此处找到的azure-sdk-for-net的一部分:github.com/Azure/azure-sdk-for-net
标签: c# azure asp.net-core azure-table-storage automatic-failover