【问题标题】:Azure storage sdk v1.3 to v2 => SetConfigurationSettingPublisherAzure storage sdk v1.3 to v2 => SetConfigurationSettingPublisher
【发布时间】:2013-07-21 07:51:27
【问题描述】:

自从“SetConfigurationSettingPublisher”被删除后,如何在 Azure 存储 v2.0 中进行转换?

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();
      }
    }
  };
}

);

谢谢

【问题讨论】:

    标签: .net azure azure-storage


    【解决方案1】:

    根据Windows Azure Storage Client Library 2.0 Breaking Changes & Migration Guide

    CloudStorageAccount.SetConfigurationSettingPublisher 已被移除。相反,StorageCredentials 的成员现在是可变的,允许用户通过提供的 UpdateKey 方法简单地改变与给定客户端关联的 StorageCredentials 实例,从而以更简化的方式完成类似的场景。

    根据应用程序的要求,您可以直接使用CloudConfigurationManager.GetSetting() 方法,如Upgrading to Azure Storage Client 2.0 中所述:

    var someSetting = CloudConfigurationManager.GetSetting(settingKey);
    

    如果您需要在角色实例运行时响应配置更改,您可以订阅RoleEnvironment.ChangingRoleEnvironment.Changed 事件,如Read Configuration Settings for the Storage Client Library and Handle Changed SettingsResponding to Role Topology Changes 中所述。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-12-27
      • 2020-10-27
      • 2012-01-25
      • 1970-01-01
      • 2019-06-09
      • 2020-11-18
      • 2021-08-17
      相关资源
      最近更新 更多