Setting up your environment
I have a full instance of SQL 2008 and don’t want to screw with Express. The dev fabric stuff by default looks for an express instance to setup. Luckily other people have already chased this down: Activating Azure Storage Service for Non SQL Express. Which basically says to go to the command line and type this:
DSInit /sqlInstance:. /forceCreate
Which can be found in C:\Program Files\Windows Azure SDK\v1.1\bin\devstore
Configuration
Once your environment is up and running you’ll need to fix up the connection strings being used. ServiceConfiguration.cfg will contain settings like DataConnectionString and DataConnectionString which you will need to configure. For development you can just set the value to “UseDevelopmentStorage=true”. When you deploy to the cloud you’ll have to change these settings, but for now this will work. It will look like:
<ConfigurationSettings>
<Setting name="DiagnosticsConnectionString" value="UseDevelopmentStorage=true" />
<Setting name="DataConnectionString" value="UseDevelopmentStorage=true" />
</ConfigurationSettings>
Queues
Azure Storage Queues are pretty easy. You can store messages up to 8K in size in the queue. Because of the way the API works the message must be XML serializable. So if you want to pass a block of binary data you will need to base64 encode it.
Working with a queue involves three operations: add, get and delete. For example: say you have a system that breaks RSA keys. One program gets the key, stores it in a table and puts a work ticket in the queue. Another program grabs a work ticket from the queue and then proceeds to break the key and store the result in another table. The problem is that breaking a key takes more than 30 seconds and queue items only get reserved for 30 seconds. What to do?
(ed – I was going to write a long explanation here about how to manage this but I want to focus on the class content so I’ll deal with this in a separate article).
Putting an Item in the queue:
CloudStorageAccount storageAccount = CloudStorageAccount
.FromConfigurationSetting("DataConnectionString");
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
CloudQueue queue = queueClient.GetQueueReference(_MessageQueueName);
These three lines get you the queue that contains the work tickets. To add your work ticket:
CloudQueueMessage msg = new CloudQueueMessage(ticketData);
Once the ticket is added it has 2 weeks to be removed before Azure removes it for you.
The program that actually processes the work ticket just needs to do something like:
bool done = false;
while (!done)
{
IEnumerable<CloudQueueMessage> messages = queue.GetMessages(_BlockSize);
if (_BlockSize > messages.Count())
{
done = true;
}
foreach (CloudQueueMessage message in messages)
{
string messageText = message.AsString;
queue.DeleteMessage(message);
}
}
Day 2 has just started so I’ll be back.