gpt4 book ai didi

c# - 如何将 TableClientOptions 与 TableClient 结合使用以进行 Azure 表存储重试?

转载 作者:行者123 更新时间:2023-12-03 04:54:40 24 4
gpt4 key购买 nike

我正在使用 TableClient 连接到 Azure 表存储:

https://learn.microsoft.com/en-us/dotnet/api/azure.data.tables.tableclient?view=azure-dotnet

我需要实现重试机制。我可以只做一个自定义实现,但我注意到有这个 TableClientOptions 我可以在构造函数中传递它:

https://learn.microsoft.com/en-us/dotnet/api/azure.data.tables.tableclientoptions?view=azure-dotnet

它具有 RetryOptions 类型的 Retry 属性:

https://learn.microsoft.com/en-us/dotnet/api/azure.core.retryoptions?view=azure-dotnet

所以我假设使用这个我会这样做:

TableClientOptions opts = new TableClientOptions(TableClientOptions.ServiceVersion.V2019_02_02);
opts.Retry = new RetryOptions
{
Delay = TimeSpan.FromSeconds(5),
Mode = RetryMode.Fixed,
MaxRetries = 5
};

TableClient tablClient = new TableClient(connStr, tblName, opts);

我的问题是第 3 行失败,因为 RetryOptions 上没有公共(public)构造函数。它提供的构造函数是内部的,所以我什至不能只创建一个继承类。

ClientOptions 类型上还有一个公共(public)静态 Default 实例,因此我尝试在其中设置值,但也没有显示任何结果。

所以我的问题是:如何使用这些选项来利用建议的重试机制?

最佳答案

只需设置 Retry 属性,而不是创建 RetryOptions 的新实例:

    TableClientOptions opts = new TableClientOptions(TableClientOptions.ServiceVersion.V2019_02_02);
opts.Retry.Delay = TimeSpan.FromSeconds(5);
opts.Retry.Mode = RetryMode.Fixed;
opts.Retry.MaxRetries = 5;

关于c# - 如何将 TableClientOptions 与 TableClient 结合使用以进行 Azure 表存储重试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71827419/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com