Imagine a Worker Role that continuously polls a Windows Azure Storage Queue. It probably got it’s configuration settings when the Role instance started and it might not use the CloudConfigurationManager to refresh its configuration for every pull. This is where the Changing and Changed events come in. They allow you to build a strategy to deal efficiently with configuration changes.
Details
The Changing event and the Changed event are used together to identify and manage configuration changes to the service model. By using the Changing event, an instance can respond to a configuration change in one of the following ways:
Accept the configuration change while it is running, without going offline.
Set the Cancel property of RoleEnvironmentChangingEventArgs to true to take the instance offline, apply the configuration change, and then bring the instance back online.
By using the Cancel property, you can ensure that the instance proceeds through an orderly shutdown sequence and is taken offline before the configuration change is applied. During the shutdown process, Windows Azure raises the Stopping event, and then runs any code in the OnStop method.
You have a limited amount of time to accept or cancel the Changing event. Make sure your event handler can return in a timely manner.
You may want to cancel the Changing event if:
- Your role instance does not support configuration changes while it is running, and requires recycling in order to apply the change.
- Your role instance is performing work that should not be disrupted by a configuration change, and needs to proceed through the shutdown sequence before applying the change.
The RoleEnvironmentChangingEventArgs class provides a Changes property that returns a collection of the configuration changes that are about to be applied to the instance. Objects in this collection can be one of the following types:
- The RoleEnvironmentConfigurationSettingChange class represents a change to the value of a configuration setting. Its ConfigurationSettingName property returns the name of the configuration setting that is being changed.
- The RoleEnvironmentTopologyChange class represents a change to the topology of the service. A change in topology is the addition or removal of instances of a role. TheRoleName property returns the name of the role whose instance count is being changed.