Database Reference
In-Depth Information
CloudQueue queue = queueClient.GetQueueReference("queue_name");
queue.CreateIfNotExist();
To insert a message into an existing queue, you need to create the message with the method
CloudQueueMessage() and then add the message to the existing queue with the following
code:
CloudQueueMessage message = new CloudQueueMessage("message_content");
queue.AddMessage(message);
You can modify the content of a message stored in a queue. In the process, you will irst
get the message with the method GetMessage(). Next, modify the message with the method
SetMessageContent(). hen, update the message with the method UpdateMessage(). he code for
changing the content of a message is given below:
CloudQueueMessage message = queue.GetMessage();
message.SetMessageContent("Modified_Message") ;
queue.UpdateMessage(message,
TimeSpan.FromSeconds(0.0),MessageUpdateFields.Content |
MessageUpdateFields.Visibility);
With the PeekMessage method, you can peek at the next message in a queue with the follow-
ing code:
CloudQueueMessage peekedMessage = queue.PeekMessage();
You can delete a message from a queue with the method DeleteMessage(). he process can be
done in two steps. You irst retrieve the message with the method GetMessage(). hen, delete the
message with the method DeleteMessage(). he code for deleting a message from a queue is given
below:
CloudQueueMessage Message = queue.GetMessage();
queue.DeleteMessage(Message);
You can also delete a queue and all the messages contained in it with the method Delete(). he
following is the code for deleting an entire queue:
CloudQueue queue = queueClient.GetQueueReference("queue_name");
queue.Delete();
ACTIVITY 11.3
USING QUEUE STOR AGE
his activity will illustrate the use of Queue storage. he web role will be used to create a
message and upload the message to the queue. he message includes a new member's infor-
mation including the new member's name, e-mail, club, and major. A worker role will be
created to process the message by reading the message in the queue, ind out which club the
new member is enrolled, and retrieve the information about the students who enrolled in the
same club. he activity will accomplish the following task:
 
Search WWH ::




Custom Search