【问题标题】:Set timeout on Azure Storage operations设置 Azure 存储操作超时
【发布时间】:2018-07-20 11:20:48
【问题描述】:

使用 Azure 存储时,如果您使用 REST,我发现有一种方法可以设置 timeout on blob operationson table operations

但是,我们正在使用通过 WindowsAzure.Storage NuGet 包 (v8.4.0) 提供的 C# 客户端。而且我看不到任何方法可以在这里指定超时

var storageAccount = CloudStorageAccount.Parse("UseDevelopmentStorage=true;DevelopmentStorageProxyUri=http://127.0.0.1"); // local storage for testing
var blobClient = storageAccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference("mycontainer");
container.CreateIfNotExists();
var blobReference = container.GetBlockBlobReference("my/blob.pdf");

我已经尝试过查看CloudBlobClientStorageAccount 上的可用属性/方法,但没有找到任何类似超时设置的东西。

如果我可以在一个地方(在连接字符串中??)设置 timout 并且在所有操作中都使用它,那将是理想的。但是如何在 C# 客户端中执行此操作?

【问题讨论】:

  • 您是否尝试过使用CloudBlobClient.DefaultRequestOptions
  • @DavidG 感谢您提供指向 DefaultRequestOptions 的链接。我完全忘记了这一点。
  • @DavidG 这可能是答案。我会在星期一尝试并报告。
  • 对于java中的追随者,它是uploadWithResponse(BlobParallelUploadOptions options, Duration timeout, Context context)

标签: c# azure azure-storage azure-table-storage azure-blob-storage


【解决方案1】:

请查看BlobRequestOptions 类中的ServerTimeout 属性。所以您的代码将是:

            var storageAccount = CloudStorageAccount.Parse("UseDevelopmentStorage=true;DevelopmentStorageProxyUri=http://127.0.0.1"); // local storage for testing
            var blobClient = storageAccount.CreateCloudBlobClient();
            var container = blobClient.GetContainerReference("mycontainer");
            container.CreateIfNotExists(new BlobRequestOptions()
            {
                ServerTimeout = TimeSpan.FromSeconds(90)
            });

【讨论】:

猜你喜欢
  • 2016-01-06
  • 2011-01-16
  • 2017-09-09
  • 1970-01-01
  • 2015-02-02
  • 2013-10-15
  • 2011-09-05
  • 2011-06-25
  • 2019-02-12
相关资源
最近更新 更多