Basics Of Queue Storage

In this article, I will explain the basics of Azure Queue storage. Azure Queue storage is a Service to store large numbers of messages, which can be accessed from anywhere, using HTTP or HTTPS. A single Queue storage contains many messages and from this article, I will explain how to write the code with .NET for Azure Queue storage to insert and delete a queue.

Introduction

In this article, I will explain the basics of Azure Queue storage. Azure Queue storage is a Service to store large numbers of messages, which can be accessed from anywhere, using HTTP or HTTPS. A single Queue storage contains many messages and from this article, I will explain how to write the code with .NET for Azure Queue storage to insert and delete a queue.

Prerequisites

  • Visual Studio 2017.
  • Azure storage client library for .NET.
  • Azure configuration manager for .NET.
  • an active |Azure subscription.

Creating a Windows Console Application project in Visual Studio

Step 1

Open Visual Studio.

Step 2

Click File-> New-> Project.

 Creating a Windows Console Application

Step 3

Click from the template-> Visual C#-> Console app (.NET framework) and provide a name for the Application and click OK.

Visual Studio Console Application 

Step 4

Now we need to install the NuGet packages, so we need to install Microsoft Azure storage client library for .NET.

We need to install Microsoft Azure configuration manager library for .NET.

Step 5

Right click on Project Solution Explorer-> Choose Manage NuGet packages.

Browse for windowsazure.storage and install the storage client library.

Now install windowsazure.configurationmanager and click install with Azure configuration manager.

Manage NuGet packages windowsazure.storage

windowsazure.configurationmanager 

Step 6

Now we need to insert the message into the existing queue. First we need to create a new queue message and delete it so the message can be added. The code is provided below.
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6. using Microsoft.Azure;  
  7. using Microsoft.WindowsAzure.Storage;  
  8. using Microsoft.WindowsAzure.Storage.Queue;  
  9. using Microsoft.Azure;  
  10. namespace queue_storage {  
  11.     class Program {  
  12.         static void Main(string[] args) {  
  13.             CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));  
  14.             CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();  
  15.             CloudQueue queue = queueClient.GetQueueReference("myqueue");  
  16.             queue.CreateIfNotExists();  
  17.             CloudQueueMessage message = new CloudQueueMessage("hai");  
  18.             queue.AddMessage(message);  
  19.             queue.Delete();  
  20.         }  
  21.     }  
  22. }   

To delete Queue messages, we need to call the delete method of Queue object.

Now we have seen the basics of Queue storage and now I will publish it as Azure WebJob.

Step 6

Right click on Project Explorer and select Publish as Azure WebJob.

Publish as Azure WebJob 

Step 7

From the Add Azure WebJob dialog box, we need to provide the WebJob name and the name should have the alphabets or the numbers. Select WebJob run mode and click OK.

Add Azure WebJob 

Step 8

We can publish it as an Azure app Service and select Microsoft Azure app Service and select Add account.

Azure app Service 

 Azure app Service

Step 9

You will be directed to an Azure portal for the login with your Id and a password.

Azure App Service 

Step 10

The configuration app Service plan dialog box will appear and the app Service plan name must be provided. Select the location and the size.

Configure App Service Plan 

Step 11

Create a new resource group for an Azure WebJob and click Create.

Azure WebJob 

Step 12

Click-Publish after validating the Web deploy configurations and the Web publish activity will take place. It can take few more minutes for the deployment and a link will be provided in an ouput and by clicking the link, you can be directed to the hyperlink page.

Azure WebJob 

App service app 

I hope you learned about the basics of Queue storage and the deployment of Azure WebJob. Thank you.