我有一个控制台应用程序,它将作业上传到在云中运行的工作人员。该应用程序连接到 Azure 存储,并将一些文件上传到 blob,并将一些消息放入队列。目前,我正在使用开发存储。我实际上想知道我的客户端应用程序连接到存储的状态。即使我根本没有任何连接,我可以创建一个queueClient吗?它实际上在哪一步尝试发送一些网络包?我实际上需要某种机制来检查连接的存在和存储帐户的有效性。
客户端不会发送任何消息,直到您在存储上调用命令 - 例如,直到您尝试获取或放置 blob、容器或队列的属性 - 例如在下面的示例代码中(来自http://msdn. microsoft.com/en-us/library/gg651129.aspx)然后消息将发送到 3 个特定位置:
// Variables for the cloud storage objects.
CloudStorageAccount cloudStorageAccount;
CloudBlobClient blobClient;
CloudBlobContainer blobContainer;
BlobContainerPermissions containerPermissions;
CloudBlob blob;
// Use the local storage account.
cloudStorageAccount = CloudStorageAccount.DevelopmentStorageAccount;
// If you want to use Windows Azure cloud storage account, use the following
// code (after uncommenting) instead of the code above.
// cloudStorageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=http;AccountName=your_storage_account_name;AccountKey=your_storage_account_key");
// Create the blob client, which provides
// authenticated access to the Blob service.
blobClient = cloudStorageAccount.CreateCloudBlobClient();
// Get the container reference.
blobContainer = blobClient.GetContainerReference("mycontainer");
// Create the container if it does not exist.
// MESSAGE SENT
blobContainer.CreateIfNotExist();
// Set permissions on the container.
containerPermissions = new BlobContainerPermissions();
// This sample sets the container to have public blobs. Your application
// needs may be different. See the documentation for BlobContainerPermissions
// for more information about blob container permissions.
containerPermissions.PublicAccess = BlobContainerPublicAccessType.Blob;
// MESSAGE SENT
blobContainer.SetPermissions(containerPermissions);
// Get a reference to the blob.
blob = blobContainer.GetBlobReference("myfile.txt");
// Upload a file from the local system to the blob.
Console.WriteLine("Starting file upload");
// MESSAGE SENT
blob.UploadFile(@"c:\myfiles\myfile.txt"); // File from local storage.
Console.WriteLine("File upload complete to blob " + blob.Uri);
Run Code Online (Sandbox Code Playgroud)
检查是否具有连接性的一种方法是在已知容器上使用一些简单的函数,例如 或 - 这些为您提供了一种简单快速的方法来检查连接性CreateIfNotExist()。GetPermissions()您还可以使用 BlobRequestOptions 指定超时,以确保您的应用程序不会挂起 ( http://msdn.microsoft.com/en-us/library/ee772886.aspx )
请注意不要过于频繁地检查连接 - 每 10000 次成功检查将花费您 0.01 美元
| 归档时间: |
|
| 查看次数: |
17170 次 |
| 最近记录: |