Creating an Azure Queue Service
This simple tutorial demonstrates how to create a message on a queue and receive that message:
1. Set up Authentication Details and Create a New Queue
The below code adds the the storage authentication details, creates a queue storage object (which is the storage container that the Message Queues are placed in), then creates a message queue and finally adds a message to that queue:
string accName = “devacc1″;
string accKey = “accountKeyStringxxxx”;
string address = “http://127.0.0.1:10001″;
StorageAccountInfo acObj = new StorageAccountInfo(new Uri(address), null, accName, accKey);
QueueStorage qsObj = QueueStorage.Create(acObj);
MessageQueue mqObj = qsObj.GetQueue(“azureSupportString”);
mq.CreateQueue();
Message msgObj = new Message(DateTime.Now.ToString());
mqObj.PutMessage(msgObj);
2. Receiving a Message from the Queue
The code for receiving a message from a queue is very straightforward. Use the GetMessage method of the MessageQueue with the time out in seconds passed in as a parameter. This timeout is the time that routine has a lock on the message, if it is not deleted within the timeout time other processes will be able to access it.
The GetMessage method returns null if there is no message on the queue so your code needs to check for that. Also note that the message remains on the queue if it is not deleted so call the DeleteMessage method to delete the message.
Message msgObj = mqObj.GetMessage(3);
if (msgObj != null)
{
Console.WriteLine(msgObj.ContentAsString());
mqObj.DeleteMessage(msgObj);
}
We can also add Queue Polling to this routine




20. Feb, 2010 







No comments yet... Be the first to leave a reply!