Brendan Enrick's Blog

Daily Software Development.


Comments (0)
Tagged as:

Default Azure Storage Information

by Brendan Enrick Tuesday, November 4 2008 14:33

The cloud is nice and useful, but there is one feature which is vitally important to most applications in my opinion. The storage which is used in Azure pretty much will need to be used by every application. One of the reasons for this is because there is a little bit of management of processes which needs to be done. This I've noticed requires a combination of the Queues and the Tables.

Queues are great because roles are able to queue up work which needs to be done. This helps make sure that all required tasks can be completed. Without these communication between the processes could get a bit messy. Also the information being worked with needs to be stored in a shared location which all of the roles and their instances have access to. The storage makes this work.

For these apps you don't use the standard configuration files to store your config settings. There is a file in the Cloud project called ServiceConfiguration.csfg, and this file is where the ConfigurationSection is located. This is where you define the settings for connecting to your storage when it is in the cloud. You will also have your configuration information stored in your web.config, and this will make things nice and easy. Since there are methods to get your configuration information which know to check the correct location.

For now these connections are made using http, so these "endpoints" are simply URLs. For local work the dev fabric and the storage are local. Because of this everyone has the same default settings for their storage. A lot of people are probably going to be looking for these default settings so to make it easy to find, here they are.

These are the AppSettings ones in the normal configuration file.

<appSettings>
  <add key="AccountName" value="devstoreaccount1"/>
  <add key="AccountKey" value="Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="/>
  <add key="BlobStorageEndpoint" value="http://localhost:10000"/>
  <add key="QueueStorageEndpoint" value="http://localhost:10001"/>
  <add key="TableStorageEndpoint" value="http://localhost:10002"/>
</appSettings>

These are the ones in the ServiceConfiguration.csfg file.

<ConfigurationSettings>
  <Setting name="BlobStorageEndpoint" value="http://127.0.0.1:10000/" />
  <Setting name="QueueStorageEndpoint" value="http://127.0.0.1:10001/" />
  <Setting name="TableStorageEndpoint" value="http://127.0.0.1:10002/" />
  <Setting name="AccountName" value="devstoreaccount1"/>
  <Setting name="AccountSharedKey" value="Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="/>
</ConfigurationSettings>

If you need access in both a WebRole and a WorkerRole this config section can be added to each one.

Also because you have added this to that configuration file you will need to add the definition of these to the ServiceDefinition.csdef file in the following way.

<ConfigurationSettings>
  <Setting name="BlobStorageEndpoint"/>
  <Setting name="QueueStorageEndpoint"/>
  <Setting name="TableStorageEndpoint"/>
  <Setting name="AccountName"/>
  <Setting name="AccountSharedKey"/>
</ConfigurationSettings>

If you don't have this file matching the configuration you will get this nasty error message which doesn't tell you much. Thanks for telling me "Invalid configuration file." It doesn't say what file or what is wrong or anything.

Invalid configuration file

When you need to access Azure storage you will be using some of this information. Some helper methods have been created which access these values from your configuration. These will help you get StorageAccountInfo classes. You can use them in this way.

StorageAccountInfo queueAccount = StorageAccountInfo.GetDefaultQueueStorageAccountFromConfiguration();
StorageAccountInfo blobAccount = StorageAccountInfo.GetDefaultBlobStorageAccountFromConfiguration();
StorageAccountInfo tableAccount = StorageAccountInfo.GetDefaultTableStorageAccountFromConfiguration();

UPDATE: I forgot to mention when I first posted this that the Storage classes for this early release of Windows Azure are kept in one of the sample projects. It is the StorageClient sample project and the namespace needed is Microsoft.Samples.ServiceHosting.StorageClient. This will change once they've gotten some more substantial libraries set up for accessing Azure Storage.

This keeps things nice and clean, and makes connecting a lot easier.

Once you have these AccountInfo objects you can use them in the constructors for your service classes which give you access to the storage. You can access that storage using the following code.

QueueStorage queueService = QueueStorage.Create(queueAccount);
BlobStorage blobService = BlobStorage.Create(blobAccount);
 
TableStorage tableService = TableStorage.Create(tableAccount);
TableStorage tableService = TableStorage.CreateTablesFromModel(typeof(MyClass), tableAccount);

Please note that the table storage is slightly different from the other two. They are much easier since they don't vary in structure. I recommend you create that service based on a specific model class you have already defined. It should inherit from the TableStorageEntity class.

Now you're ready to start working with Azure storage.

Comments (0)
Tagged as:

Microsoft Announced Windows Azure at PDC

by Brendan Enrick Monday, October 27 2008 19:02

In the recent Keynote here at Microsoft PDC, they just announced what they're calling an operating system for the cloud. Windows Azure is a platform for developers to create applications which are highly scalable. Over a month ago I was at Microsoft's campus looking at their Red Dog project. Now we've all learned that Microsoft has named this project more officially as Windows Azure. With this new project they are launching their CTP solution. With this they have a live cloud on which people can publish their cloud-based applications.

For now hosting applications on the cloud will be free of charge for people. Once Microsoft moves further along with their cloud hosting abilities this will be a pay service. They've not said yet how much these services will cost or even really what you'll be charged for. It looks like there will be a lot of new Azure stuff coming out soon.

One of the neatest applications I've seen here is one that I saw a preview of when it was in its early development in Redmond. Bluehoo is a neat application. It is targeted to mobile users. It allows them to have their phones communicate with eachother and with central services hosted on the cloud. This allows all of the users to know who is around them and what those people's interests are based on profiles the users specify. There is so much potential for this application I can't wait to see what they do with it.

It would be great to be able to walk into an establishment of some kind and see that there are people sharing your common interests. You'll be able to start conversations with people based on this. According to the Bluehoo guys the application will be available as a beta service online later today. Go check it out.