Hello, Cloud! Azure Queues

Published: Fri 19 August 2011
By Jason

In Azure.

Note: I'm just getting started with Azure, and this post is mostly a tool to help me figure things out. If anything below is wrong and/or stupid, just let me know and I'll fix it. :)

Step 0: Getting to the point where you can actually write some code.

A Visual Studio solution needs to have a "Windows Azure Project" in it. This project doesn't really have code -- it appears to mainly serve as something where you can configure how your own personal cloud will run on your dev-box, which of the other projects in your solution are Azure Roles (typically either web or worker roles), and gives you something to hit F5 on to actually run your stuff in an Azure-like dev environment.

This project type is under File > Add New Project > Cloud. If Azure hasn't been set up for Visual Studio yet there's a fairly convenient path from this Add New Project dialog to downloading and installing all the Azure tools. This took about 5 or 10 minutes and was painless.  I'm using Azure SDK 1.4, which was released in August of 2011.

Next you'll need either a web role project or a worker role project added to your solution and connected with your Cloud project.

Last, you'll need to Add Reference to some Azure dll's. These apparently don't make into the GAC when Azure tools are installed; I found mine by manually poking around the file system. I added references to:

  • C:\Program Files\Windows Azure SDK\v1.4\bin\Microsoft.WindowsAzure.StorageClient.dll
  • C:\Program Files\Windows Azure SDK\v1.4\bin\Microsoft.WindowsAzure.DevelopmentStorage.Store.dll

We can write some code now - yay!

Step 1: Cracking into the API

I've got an ASP.NET web project here, and my self-imposed mission is, on application startup, launch two threads, one to push messages onto the queue at random times, and another thread to pick them and "process" them. Let's start with this:

using System;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;
using System.Web;

public class MvcApplication : HttpApplication {

    protected void Application_Start() {
        var client = CloudStorageAccount.DevelopmentStorageAccount.CreateCloudQueueClient();
    }

}

Notes:

  • CloudStorageAccount is in the Microsoft.WindowsAzure namespace and has some static methods for getting either a "Development" storage account (as here) or to load account information from configuration.
  • CreateCloudQueueClient is an extension method in the Microsoft.WindowsAzure.StorageClient namespace. There are corresponding extensions for blob and table storage clients.

Step 2: Get a reference to a queue

(I never finished the post from here.)

Comments !

links

social