我是 Azure (2.2) 的新手,正在尝试更改配置。我在我想使用的 azure 配置中有一个标志。特别是,停止从队列中处理,并帮助进行暂存与生产迁移。
我已经从门户中的 config 上传了新配置,但在玩了几个小时之后,它似乎总是会破坏并重新创建实例。
有没有办法在不销毁实例的情况下更新配置文件?
谢谢
* 编辑和回答回复 *
我确实玩过改变/改变的事件。他们似乎确实运行了,但重启后就消失了。
我的测试,我希望我能很好地解释我自己,但是如果你有一个静态计数器变量并且你将它默认为 1 并且在变化/变化的事件中并在每次事件触发时递增变量。我还将一个默认为“JUNK”的静态变量设置为事件中设置的新配置值。多次上传具有大量值的配置并将静态与直接从配置读取的内容进行比较后的结果总是静态返回默认值并读取新的配置标志。应用程序域已重新启动并再次运行所有初始化代码。这意味着我可以忽略设置更改事件并上传配置并让初始化再次发生,这是我试图避免的。
请您参考如下方法:
我不认为角色实例会在您更改配置设置值时被销毁并重新创建。角色实例可能会被关闭以应用该设置并重新启动(换句话说重新启动)。如果您运行多个实例,则更改一次应用于一个实例,以便您的应用程序继续运行。
RoleEnvironment类有一个 Changing可用于该目的的事件。看看那个。我相信,如果您将 Cancel 属性设置为 false,将应用更改,而不会删除实例。
来自Changing事件文档页面:
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.
