Queue Service is a windows azure storage type where we can store data on basis of queue concept i.e. first in first out. It will display those message first which was processed earlier.
The Queue service stores message that may be read by any client who has access to the storage account. A queue can contain an unlimited number of messages, each of which can be up to 64 KB in size using version 2011 – 08 – 18 or newer. For previous versions, the maximum size of a message is 8 KB. Messages are generally added to the end of the queue and retrieved from the front of the queue.
If you need to store messages larger than 64 KB, you can store message data as a blob or in a table, and then store a reference to the data as a message in a queue.
The Queue service exposes the following resources via the REST API:
· Account: The storage account is a uniquely identified entity within the storage system. The account is the parent namespace for the Queue service. All queues are associated with an account.
· Queue: A queue stores messages that may be retrieved by a client application or service.
· Messages: Messages are XML-compliant and may be up to 8 KB in size.
Now I am going to explain how to create queue and how to add a message in a queue in a windows azure application.
· Open Microsoft Visual Studio 2010 as an administrator.
· To create a new project File – New – Project.
· Select Cloud template from the Installed Templates.
· Select Windows Azure Project and enter the name of the project as QueueService.
· Click OK to proceed.
· To add an asp.net web role to the solution, choose ASP.NET Web Role and then choose the right arrow. The roles are displayed in the Windows Azure solution pane of the dialog box. You can rename it as QueueService.
· Click OK to add.
After adding web role, delete all the files from the PersonalInfo web role in the solution explorer except References, Properties, WebRole.cs.
· Add a web form (Default.aspx) in a web role.
· Add a new web.config file.
· Modify the Default.aspx as shown below:
<asp:TextBox ID="txtMessage" runat="server" TextMode="MultiLine" Rows="5" Columns="50"></asp:TextBox>
<asp:Button ID="btnAddMsg" runat="server" Text="Add Message" onclick="btnAddMsg_Click" />
<asp:Label ID="lblMsgs" runat="server"></asp:Label>
Add the following additional namespace in a Default.aspx.cs :
After adding namespace, add the following code on the click event of button to create a queue service and add a message in a queue:
protected void btnAddMsg_Click(object sender, EventArgs e)
var connectionString = RoleEnvironment.GetConfigurationSettingValue
CloudStorageAccount storageAccount =
CloudQueueClient queueClient =storageAccount.CreateCloudQueueClient();
CloudQueue queue =queueClient.GetQueueReference("msgservice");
CloudQueueMessage message = new CloudQueueMessage(txtMessage.Text);
You also have to add the setting (DataConnectionString) in a web role configuration file:
· Right click on web role, select Properties.
· Move to Settings tab.
· Add setting (DataConnectionString) as shown in below figure:
Now press F5 to run your application. When you enter some text and click on Add message, it will add the message in a queue and display it in the label. The output should something like below:
I think after reading this article you can easily create queue and store messages in a queue in a windows azure application.