【问题标题】:In Service Fabric, can I alter the Arguments in the ServiceManifest.xml file using Application Parameters?在 Service Fabric 中,是否可以使用应用程序参数更改 ServiceManifest.xml 文件中的参数?
【发布时间】:2016-09-26 02:17:38
【问题描述】:

我有一个 ApplicationManifest.xml 文件,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<ApplicationManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/2011/01/fabric"
   ApplicationTypeName="ServiceFabricTestType" ApplicationTypeVersion="1.9">
   <Parameters>
     <Parameter Name="Prop_BehavioursPath" DefaultValue="behaviours.yml"/>
     <Parameter Name="Prop_AliasesPath" DefaultValue="aliases.yml"/>
   </Parameters>
  <ServiceManifestImport>
  <ServiceManifestRef 
    ServiceManifestName="SummaryGenerator" 
    ServiceManifestVersion="1.9.0.0" 
    />
  </ServiceManifestImport>
</ApplicationManifest>

我想使用参数来调整我的访客托管服务的参数,在 ServiceManifest.xml 文件中声明,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<ServiceManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/2011/01/fabric"
   Name="SummaryGenerator" Version="1.9.0.0">
   <ServiceTypes>
     <StatelessServiceType ServiceTypeName="SummaryGenerator" UseImplicitHost="true"/>
   </ServiceTypes>
   <CodePackage Name="code" Version="1.9.0.0">
   <EntryPoint>
     <ExeHost>
        <Program>MyProgram.exe</Program>
        <Arguments>&quot;LoadFrom=[Prop_AliasesPath]|[Prop_BehavioursPath]&quot;</Arguments>
        <ConsoleRedirection FileRetentionCount="5" FileMaxSizeInKb="2048"/>
     </ExeHost>
   </EntryPoint>
  </CodePackage>
</ServiceManifest>

这显然不起作用,因为进入 Arguments 的属性被逐字处理,而不是从参数值解析。

我真正想做的是能够启动服务并为 Prop_BehavioursPath 和 Prop_AliasesPath 传递不同的值。在 Service Fabric 中是否有更好的方法来执行此操作?

正在运行的应用程序不知道 Service Fabric,将配置推送到它的唯一方法是通过命令参数。

【问题讨论】:

    标签: azure azure-service-fabric


    【解决方案1】:

    看起来您不能这样做...相反,您可以尝试一种解决方法,您可以编写一个小的 .NET 包装器来读取 sf 配置,然后启动您的来宾可执行文件。您可以从子进程重定向 stdin/stdout 并挂钩到它的退出事件,以便主进程在子进程终止时终止。

    【讨论】:

    • 喜欢使用装饰器模式进一步抽象运行时的想法,这绝对是我正在寻找的解决方案!
    • 如果你能解决它,我很乐意看到它......因为它所做的只是启动一个进程,它应该适用于任何事情。
    • 如果我找到更直接的路线,我会在这里发布答案
    • @tommed 你找到更直接的路线了吗?我目前面临同样的问题。
    • 不,由于缺乏响应,我现在使用 Kubernetes 作为我的基础架构,并且对服务/社区/支持/文档​​非常满意
    【解决方案2】:

    与参数类似,您可以在 ServiceManifest.xml 中定义环境变量(例如 Prop_AliasesPath 和 Prop_BehavioursPath),然后在 ApplicationManifest.xml 中覆盖它们的值。那么你有两个选择:

    选项 1: 即使您的入口点 MyProgram.exe 不支持服务结构,它也可以读取环境变量。

    选项 2: 为避免读取 MyProgram.exe 中的环境变量,您可以使用批处理文件作为入口点,并从中调用“MyProgram.exe LoadFrom=%Prop_AliasesPath%%Prop_BehavioursPath%”

    有关覆盖环境变量的更多信息: https://dzimchuk.net/using-code-package-environment-variables-in-service-fabric/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-23
      • 2023-02-03
      • 2019-04-03
      • 2019-04-05
      • 2019-04-25
      相关资源
      最近更新 更多