gpt4 book ai didi

.net - 如何更改 Azure 队列存储 QueueClient.CreateIfNotExists() 的默认超时?

转载 作者:行者123 更新时间:2023-12-03 00:59:35 26 4
gpt4 key购买 nike

我正在尝试使用 Azure 队列的 v12 SDK。

当我创建队列实例时,我在应用程序启动时要做的第一件事是查看队列是否存在。 Based on the typical documentation examples :

// Get the connection string from app settings
string connectionString = ConfigurationManager.AppSettings["storageConnectionString"];

// Instantiate a QueueClient which will be used to create and manipulate the queue
QueueClient queueClient = new QueueClient(connectionString, "myqueue");

// Create the queue
queueClient.CreateIfNotExists();

这很棒..但是..如果代码无法访问队列存储(例如错误的连接字符串/本地主机存储模拟器尚未100%启动等)..那么它会挂起很长时间..在我的 Polly 代码启动之前,它是“重试策略”。

问题:

  • 有没有办法让客户端在 5 秒后失败/退出,而不必等待 30 或 60 秒(就像这是一些默认设置,内心深处)。
  • 客户端是否自动重试?如果是,这意味着我不需要我的 polly 代码...

最佳答案

Is there a way to let the client fail/quit after 5 seconds instead ofme having to wait 30 or 60 seconds (like that's some default setting,deep down).

请尝试下面的代码。在新的 SDK 中设置请求超时的方法有点复杂。在代码中,我强制请求在 10 毫秒后超时,并指示 SDK 不要重试该请求 (options.Retry.MaxRetries = 0;)

    static void Main(string[] args)
{
HttpClient httpClient = new HttpClient()
{
Timeout = TimeSpan.FromMilliseconds(10)
};
var transport = new HttpClientTransport(httpClient);
QueueClientOptions options = new QueueClientOptions()
{
Transport = transport,
};
options.Retry.MaxRetries = 0;
var queueClient = new QueueClient(connectionString, "test", options);
queueClient.CreateIfNotExists();
Console.WriteLine("Press any key to continue.");
Console.ReadKey();
}

Does the client auto-retry? If yes, this means I don't need my pollycode...

是的,确实如此。这是默认的重试策略:

enter image description here

关于.net - 如何更改 Azure 队列存储 QueueClient.CreateIfNotExists() 的默认超时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62834073/

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