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.
Step 3
Click from the template-> Visual C#-> Console app (.NET framework) and provide a name for the Application and click OK.
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.
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.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Microsoft.Azure;
- using Microsoft.WindowsAzure.Storage;
- using Microsoft.WindowsAzure.Storage.Queue;
- using Microsoft.Azure;
- namespace queue_storage {
- class Program {
- static void Main(string[] args) {
- CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
- CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
- CloudQueue queue = queueClient.GetQueueReference("myqueue");
- queue.CreateIfNotExists();
- CloudQueueMessage message = new CloudQueueMessage("hai");
- queue.AddMessage(message);
- queue.Delete();
- }
- }
- }
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.
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.
Step 8
We can publish it as an Azure app Service and select Microsoft Azure app Service and select Add account.
Step 9
You will be directed to an Azure portal for the login with your Id and a password.
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.
Step 11
Create a new resource group for an Azure WebJob and click Create.
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.
I hope you learned about the basics of Queue storage and the deployment of Azure WebJob. Thank you.