在 Azure 服务结构应用程序中存储配置值的位置
Where to store configuration values in Azure Service fabric application
我正在研究 Azure Service Fabric Reliable Actor 实施。 idea/link 我可以在哪里存储配置值(例如数据库连接字符串)以及如何在代码中访问它。
Service Fabric 应用程序由代码包、配置包和数据组成 (https://azure.microsoft.com/en-gb/documentation/articles/service-fabric-application-model/)。
您可以使用配置包来存储和检索您需要的任何类型的 key-value 对,例如一个连接字符串。请查看这篇文章 https://azure.microsoft.com/en-us/documentation/articles/service-fabric-manage-multiple-environment-app-configuration/ 了解更多信息。
您可以添加多个ApplicationParameters 文件。只需从 Cloud.Xml 复制并粘贴相同的内容并用于多个环境配置。
进行必要更改的步骤
Settings.xml 中给出的值需要在导入 ServiceManifest.xml 时在 ApplicationManifest.xml 中覆盖。下面是支持覆盖更改的代码添加他们在 ApplicationManifest.xml。
a) 先添加参数默认值
<Parameters>
<Parameter Name="StatelessService1_InstanceCount" DefaultValue="-1" />
<!-- Default Value is set to Point to Dev Database -->
<Parameter Name="DatabaseString"DefaultValue="Server=someserver.database.windows.net\;Database=DbDev;user id=[userid];password=[Password];Trusted_Connection=false;" />
</Parameters>
b) 然后在 ServiceManifestImport 中覆盖它
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="StatelessServicePkg"
ServiceManifestVersion="1.0.0" />
<ConfigOverrides>
<ConfigOverride Name="Config">
<Settings>
<Section Name="DatabaseConnections">
<Parameter Name="DbString" Value="[DatabaseString]" />
</Section>
</Settings>
</ConfigOverride>
</ConfigOverrides>
</ServiceManifestImport>
上述代码更改将覆盖 settings.xml
中的以下代码
<Section Name="DatabaseConnections">
<Parameter Name="DbString" Value="Server=someserver.database.windows.net\;Database=DbDev;user id=[userid];password=[Password];Trusted_Connection=false;" />
</Section>
总体而言,当部署应用程序时,ApplicationParameter DevParam.xml 或 QaParam.xml 或 ProdParam.xml 中的值将覆盖所有设置值。
<Parameters>
<Parameter Name="StatelessService1_InstanceCount" Value="-1" />
<Parameter Name="DatabaseString" Value="Server=someserverqa.database.windows.net\;Database=DbQA;user id=[userid];password=[Password];Trusted_Connection=false;" />
</Parameters>
除了上述信息之外,了解 ASF 覆盖应用程序设置的顺序也很重要:
Service Fabric will always choose from the application parameter file
first (if specified), then the application manifest, and finally the
configuration package (source)
更多信息:
http://www.binaryradix.com/2016/10/reading-from-configuration-within-azure.html
我正在研究 Azure Service Fabric Reliable Actor 实施。 idea/link 我可以在哪里存储配置值(例如数据库连接字符串)以及如何在代码中访问它。
Service Fabric 应用程序由代码包、配置包和数据组成 (https://azure.microsoft.com/en-gb/documentation/articles/service-fabric-application-model/)。
您可以使用配置包来存储和检索您需要的任何类型的 key-value 对,例如一个连接字符串。请查看这篇文章 https://azure.microsoft.com/en-us/documentation/articles/service-fabric-manage-multiple-environment-app-configuration/ 了解更多信息。
您可以添加多个ApplicationParameters 文件。只需从 Cloud.Xml 复制并粘贴相同的内容并用于多个环境配置。
进行必要更改的步骤
Settings.xml 中给出的值需要在导入 ServiceManifest.xml 时在 ApplicationManifest.xml 中覆盖。下面是支持覆盖更改的代码添加他们在 ApplicationManifest.xml。
a) 先添加参数默认值
<Parameters> <Parameter Name="StatelessService1_InstanceCount" DefaultValue="-1" /> <!-- Default Value is set to Point to Dev Database --> <Parameter Name="DatabaseString"DefaultValue="Server=someserver.database.windows.net\;Database=DbDev;user id=[userid];password=[Password];Trusted_Connection=false;" /> </Parameters>
b) 然后在 ServiceManifestImport 中覆盖它
<ServiceManifestImport> <ServiceManifestRef ServiceManifestName="StatelessServicePkg" ServiceManifestVersion="1.0.0" /> <ConfigOverrides> <ConfigOverride Name="Config"> <Settings> <Section Name="DatabaseConnections"> <Parameter Name="DbString" Value="[DatabaseString]" /> </Section> </Settings> </ConfigOverride> </ConfigOverrides> </ServiceManifestImport>
上述代码更改将覆盖 settings.xml
中的以下代码<Section Name="DatabaseConnections"> <Parameter Name="DbString" Value="Server=someserver.database.windows.net\;Database=DbDev;user id=[userid];password=[Password];Trusted_Connection=false;" /> </Section>
总体而言,当部署应用程序时,ApplicationParameter DevParam.xml 或 QaParam.xml 或 ProdParam.xml 中的值将覆盖所有设置值。
<Parameters> <Parameter Name="StatelessService1_InstanceCount" Value="-1" /> <Parameter Name="DatabaseString" Value="Server=someserverqa.database.windows.net\;Database=DbQA;user id=[userid];password=[Password];Trusted_Connection=false;" /> </Parameters>
除了上述信息之外,了解 ASF 覆盖应用程序设置的顺序也很重要:
Service Fabric will always choose from the application parameter file first (if specified), then the application manifest, and finally the configuration package (source)
更多信息: http://www.binaryradix.com/2016/10/reading-from-configuration-within-azure.html