我有一个 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>
我想使用参数来调整我的 guest 托管服务的参数,在 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>"LoadFrom=[Prop_AliasesPath]|[Prop_BehavioursPath]"</Arguments>
<ConsoleRedirection FileRetentionCount="5" FileMaxSizeInKb="2048"/>
</ExeHost>
</EntryPoint>
</CodePackage>
</ServiceManifest>
这显然不起作用,因为进入参数的属性被逐字对待,而不是从参数值解析。
我真正想做的是能够启动服务并为 Prop_BehavioursPath 和 Prop_AliasesPath 传递不同的值。在 Service Fabric 中是否有更好的方法来执行此操作?
正在运行的应用程序不了解 Service Fabric,将配置推送到它的唯一方法是通过命令参数。
最佳答案
看起来您无法做到这一点...相反,您可以尝试一种解决方法,编写一个小型 .NET 包装器来读取 sf 配置,然后启动 guest 可执行文件。您可以从子进程重定向 stdin/stdout 并 Hook 到其退出事件,以便主进程在子进程终止时终止。
关于azure - 在 Service Fabric 中,我可以使用应用程序参数更改 ServiceManifest.xml 文件中的参数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37488598/