Showing posts with label Queue. Show all posts
Showing posts with label Queue. Show all posts

Sunday, 16 September 2018

Delete a Queue in Microsoft Azure storage account.

In this post we are going to see how to delete a queue in Microsoft Azure storage account.

Install the Following package
1. WindowsAzure.Storage
2. Install-Package Microsoft.WindowsAzure.ConfigurationManager -Version 3.2.3

class Program
    {

        // Nuget Packages
        // -Install-Package Microsoft.WindowsAzure.ConfigurationManager -Version 3.2.3
        static void Main(string[] args)
        {
            CloudStorageAccount account = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("azureStorageAccount"));
            var queueClient = account.CreateCloudQueueClient();

            /* Get the reference of the queue */
            var testQueue = queueClient.GetQueueReference("testingqueue");

            /* Deleting the queue if exists */
            testQueue.DeleteIfExists();

        }

    }

From the above code you can learn how to delete a queue in Microsoft Azure storage account.

Create a Queue in Microsoft Azure storage account and send message to it

In this post we are going to see how to create a queue in Microsoft Azure storage account and send the message to that queue. First we have to configure the connectionstring of the storage account in the appsetting of app.config.

Install the Following package
1. WindowsAzure.Storage
2. Install-Package Microsoft.WindowsAzure.ConfigurationManager -Version 3.2.3

Queue name should be lower case otherwise it will return bad request.

Please see this link for Queue naming rules: https://msdn.microsoft.com/en-us/library/azure/dd179349.aspx.

After installing above two packages now start the coding.

class Program
    {

        static void Main(string[] args)
        {
            CloudStorageAccount account = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("azureStorageAccount"));

            var queueClient = account.CreateCloudQueueClient();

            /* Get the reference of the queue */
            var testQueue = queueClient.GetQueueReference("testingqueue");

            /* Create a Queue if not exists */
            testQueue.CreateIfNotExists();

            CloudQueueMessage message = new CloudQueueMessage("Hai sample");

            /* Adding a message to Queue */
            testQueue.AddMessage(message);


        }

    }

use the Microsoft Azure storage Explorer for viewing the queue message.
https://azure.microsoft.com/en-us/features/storage-explorer/


Output:
************





From this post you can learn how to create a queue in Microsoft Azure storage account and send the message to that queue.