您的位置:首页 > 产品设计 > UI/UE

Azure Basic - Windows Storage Enhancement (Queue)

2011-11-20 00:25 501 查看
Queue

Get messages in a batch (In Sample 1)
Poison message : use dequeuecount (In Sample 1)
Delete message: always add try-catch at multiple consumers situation (In Sample 1)
Always add time sleep to avoid "throttling" & "Money, Money, Money" (In Sample 1)
Retry Policy (Microsoft.WindowsAzure.StorageClient.RetryPolicies)
http://blogs.msdn.com/b/windowsazurestorage/archive/2011/02/03/overview-of-retry-policies-in-the-windows-azure-storage-client-library.aspx "

We strongly recommend using the exponential backoff retry policy provided by default whenever possible in order to gracefully backoff the load to your account, especially if throttling was to occur due to going over the scalability
targets posted here. You can set this manually by via [Client].RetryPolicy = RetryPolicies.RetryExponential(RetryPolicies.DefaultClientRetryCount, RetryPolicies.DefaultClientBackoff).

Generally speaking a high throughput application that will be making simultaneous requests and can absorb infrequent delays without adversely impacting user experience are recommended to use the exponential backoff strategy detailed above. However for user
facing scenarios such as websites and UI you may wish to use a linear backoff in order to maintain a responsive user experience.

Joe Giardino

"

Always use partition key in the query
Note: all messages will be encode using Base64

Sample 1

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;
using System.Threading;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string accountName = "devstoreaccount1";
string key = "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==";
string containerName = "containername";
string blobName = "blobname";

StorageCredentialsAccountAndKey credentials =
new StorageCredentialsAccountAndKey(accountName, key);

string baseUri = string.Format("http://127.0.0.1:10001/{0}", accountName);

CloudQueueClient queueStorage = new CloudQueueClient(baseUri, credentials);
//Retry Policy
queueStorage.RetryPolicy = RetryPolicies
.RetryExponential(RetryPolicies.DefaultClientRetryCount,
RetryPolicies.DefaultMaxBackoff);
CloudQueue queue = queueStorage.GetQueueReference("guestthumbs");
queue.CreateIfNotExist();

for (int i = 0; i < 20; i++)
{
var message = new CloudQueueMessage(String.Format("{0},{1},{2}",
i+":uniqueBlobName",
"entry.PartitionKey",
"entry.RowKey"));
queue.AddMessage(message);
Console.WriteLine("Input Message :" + message);
}

while (true)
{
IEnumerable<CloudQueueMessage> msgList = queue.GetMessages(32, TimeSpan.FromSeconds(20));

if (msgList == null)
{
//Time Sleep
Thread.Sleep(TimeSpan.FromSeconds(5));
}
else
{
try
{
foreach (CloudQueueMessage msg in msgList)
{
if (msg.DequeueCount < 8)
{
Console.WriteLine("Output Message : "+msg.AsString);
}
else
{
//Handle Poison Message
}
queue.DeleteMessage(msg);
}
}
catch (StorageClientException ex)
{
if (ex.ExtendedErrorInformation.ErrorCode == "MessageNotFound")
{
// pop receipt must be invalid
// ignore or log (so we can tune the visibility timeout)
}
else
{
// not the error we were expecting
throw;
}
}

}
}

}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: