Windows Azure Configurations

There are different ways on the Windows Azure platform to make and set configurations.

For the WebRole we have the web.config and for the WorkerRole we have the app.config. These config files are not new and we are used to use these. The advantage of this is, porting our current applications to the Windows Azure platform do not need many adjustments. Disadvantage these settings are only changeable with a new deploy of the application. In principal with RDP to the Role, you are able to change the settings in the web of app.config . But these changes will disappear during a reimage of the instance and are not valid for all the instances of the role.

config1config2

You can also have settings in the ServiceConfiguration.cscfg. Advantage they can be changed on the fly and are valid for all instances. After a reimage they are still available for the Roles. Disadvantage you need to change your current WebSites / Windows Services so they can use these settings.

config3config4

Changing the source code is relatively simple:

 1: RoleEnvironment.GetConfigurationSettingValue("setting")

 

Other disadvantage these settings will not automatically picked up by the running roles. You need to restart the role, but if you put this code in the OnStart method than this problem is solved.

 1: // For information on handling configuration changes
 2: // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
 3: RoleEnvironment.Changing += RoleEnvironmentChanging;

Also add this event.

 1: private void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
 2: {
 3:     Trace.WriteLine("Role Environment Changing");
 4:     // If a configuration setting is changing
 5:     if (e.Changes.Any(change => change is RoleEnvironmentConfigurationSettingChange))
 6:     {
 7:         // Set e.Cancel to true to restart this role instance
 8:         e.Cancel = true;
 9:     }
 10: }

It is important to identify which settings you have and where you put them. Are they volatile, do they never change, etc.

At this moment the settings in the ServiceConfiguration.cscfg are per Role. When having common settings for all the roles, than you need to duplicate them to every role.

Also there is no way to nest settings, there is just one level.

I hope they will change this in the future, I am convinced they do. Many of these wishes are added to http://www.mygreatwindowsazureidea.com. And I know the product teams think this site is very valuable.

Leave a Reply