Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure storage sdk v1.3 to v2 => SetConfigurationSettingPublisher

How could you convert this in Azure storage v2.0 since "SetConfigurationSettingPublisher" was deleted ?

CloudStorageAccount.SetConfigurationSettingPublisher( 
( configName, configSetter ) =>
{
  // Provide the configSetter with the initial value
  configSetter( RoleEnvironment.GetConfigurationSettingValue( configName ) );

  RoleEnvironment.Changed += ( sender, arg ) =>
  {
    if( arg.Changes.OfType<RoleEnvironmentConfigurationSettingChange>( ).Any( (change) => 
        ( change.ConfigurationSettingName == configName ) ) )
    {
      // The corresponding configuration setting has changed, so propagate the value
      if( !configSetter( RoleEnvironment.GetConfigurationSettingValue( configName ) ) )
      {
        // In this case, the change to the storage account credentials in the
        // service configuration is significant enough that the role needs to be
        // recycled in order to use the latest settings (for example, the 
        // endpoint may have changed)
        RoleEnvironment.RequestRecycle();
      }
    }
  };
}

);

Thanks

like image 257
Raph Avatar asked Jul 22 '13 14:07

Raph


1 Answers

According to Windows Azure Storage Client Library 2.0 Breaking Changes & Migration Guide:

CloudStorageAccount.SetConfigurationSettingPublisher has been removed. Instead the members of StorageCredentials are now mutable allowing users to accomplish similar scenarios in a more streamlined manner by simply mutating the StorageCredentials instance associated with a given client(s) via the provided UpdateKey methods.

Depending on your application's requirements you might simply use the CloudConfigurationManager.GetSetting() method directly, as described in Upgrading to Azure Storage Client 2.0:

var someSetting = CloudConfigurationManager.GetSetting(settingKey);

If you need to respond to configuration changes while the role instance is running, you can subscribe to the RoleEnvironment.Changing and RoleEnvironment.Changed events as described in Read Configuration Settings for the Storage Client Library and Handle Changed Settings and Responding to Role Topology Changes.

like image 116
Fernando Correia Avatar answered Sep 23 '22 03:09

Fernando Correia