Working with Windows Azure Queues

On January 12, 2010, in Azure, Development, by Mitch Milam

Since Windows Azure was only officially released in the past month, you may find a lot of the prior examples do not work because of changes made between the CTP versions and the production version. The StorageClient sample included in the Windows Azure SDK is no exception.

There are many issues you’ll face getting this working, but the first involves recompiling the StorageClient assembly using the production-level Windows Azure references.

This article walks you through what’s required to make that happen.

 

Connecting to Your Production Queues

One of the biggest problems I faced was actually connecting to the production queues on my Windows Azure Storage instance.  After spending quite a bit of time troubleshooting and browsing the Internet, I realized that StorageClient was looking for the storage endpoints, which you place in your configuration file, in a very specific format. 

Within your ServiceConfiguration.cscfg file, your role configuration should look something like this:

<Role name="WorkerRole">
  <Instances count="1" />
  <ConfigurationSettings>
    <Setting name="AccountName" value="myaccountname" />
    <Setting name="AccountSharedKey" value="secretkey" />
    <Setting name="TableStorageEndpoint" value="http://table.core.windows.net/" />
    <Setting name="QueueStorageEndpoint" value="http://queue.core.windows.net/" />
  </ConfigurationSettings>
</Role>

All you really need to change is the AccountName and AccountSharedKey settings. 

If you look at your Windows Azure management console, the AccountName is the name of your account as represented in the storage URL ( basically the first word after the http:// ). 

Note: I’ve not seen documentation on this, but it appears the only accepted format is all lower-case.

The AccountSharedKey is the Primary Access Key for the storage account.

The TableStorageEndpoint and QueueStorageEndpoint are the base URLs for your services.  The StorageClient will actually prepend your account name to the base URL to create the proper endpoint.

 

Connecting to Your Local Development Queues

It appears that you connect to your local development queue using the following configuration:

<Role name="WorkerRole">
  <Instances count="1" />
  <ConfigurationSettings>
    <Setting name="AccountName" value="devstoreaccount1" />
    <Setting name="AccountSharedKey" value="Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==" />
    <Setting name="TableStorageEndpoint" value="http://127.0.0.1:10002" />
    <Setting name="QueueStorageEndpoint" value="http://127.0.0.1:10001" />
  </ConfigurationSettings>
</Role>

 

Final Notes

I also found the Windows Azure Management Tool (MMC) to be of great assistance when needing to work with Queues.  It also has Blob support, but I’ve been using CloudBerry Explorer for Azure Blob Storage for uploading blobs.