Azure blob 客户端设置更短的超时

Azure blob client set shorter timeout

我有以下代码:

private static CloudBlobClient GetClient()
{
    var account = CloudStorageAccount.Parse(Settings.Deployment.AzureConnectionString);
    return account.CreateCloudBlobClient();
}

当 blob 客户端不存在并抛出 No connection could be made because the target machine actively refused it 时,它花费的时间太长(我相信大约一分钟左右)。

如何将超时时间减少到 5 秒左右?

据我所知,当我们只是调用CloudStorageAccount.CreateCloudBlobClient() 方法来创建Blob 服务客户端时,它不会向Azure 存储服务器发送请求。它只是创建一个 Blob 服务客户端并使用您提供的存储信息(连接字符串)来配置它。在我看来,CloudStorageAccount.CreateCloudBlobClient() 不应导致超时问题,也许您程序中的另一个代码片段会导致该问题。

Azure 存储客户端库的源代码可在 GitHub, and you could find source of CreateCloudBlobClient() 上找到。

/// <summary>
/// Creates the Blob service client.
/// </summary>
/// <returns>A <see cref="CloudBlobClient"/> object.</returns>

public CloudBlobClient CreateCloudBlobClient()
{
    if (this.BlobEndpoint == null)

    {

        throw new InvalidOperationException(SR.BlobEndPointNotConfigured);

    }
    return new CloudBlobClient(this.BlobStorageUri, this.Credentials);
}