Azure storage sdk v1.3 to v2 => SetConfigurationSettingPublisher

ⅰ亾dé卋堺 提交于 2019-12-19 17:57:29

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/17789937/azure-storage-sdk-v1-3-to-v2-setconfigurationsettingpublisher

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!