【发布时间】:2016-08-03 09:21:09
【问题描述】:
我正在尝试在单个 exe (ServiceRuntime.RegisterServiceAsync) 中注册多个 service-fabric 服务。这支持吗?如果是这样,我将如何配置它们?
例如:ServiceManifest.xml 支持 ServiceTypes 中的多个 StatelessServiceType 元素:
<?xml version="1.0" encoding="utf-8"?>
<ServiceManifest Name="EchoGatewayPkg"
Version="1.0.0"
xmlns="http://schemas.microsoft.com/2011/01/fabric"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ServiceTypes>
<StatelessServiceType ServiceTypeName="Service1Type" >
</StatelessServiceType>
<StatelessServiceType ServiceTypeName="Service2Type" >
</StatelessServiceType>
</ServiceTypes>
...
ApplicationManifest.xml 不支持 DefaultServices/Service 中的多个 StatelessService 元素:
<?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" ApplicationTypeName="EchoServiceType" ApplicationTypeVersion="1.0.0" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<Parameters>
<Parameter Name="Service1_InstanceCount" DefaultValue="1" />
<Parameter Name="Service2_InstanceCount" DefaultValue="1" />
</Parameters>
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="MyServicePkg" ServiceManifestVersion="1.0.0" />
<ConfigOverrides />
</ServiceManifestImport>
<DefaultServices>
<Service Name="MyService1">
<StatelessService ServiceTypeName="Service1Type" InstanceCount="[Service1_InstanceCount]">
<SingletonPartition />
</StatelessService>
</Service>
<Service Name="MyService2">
<StatelessService ServiceTypeName="Service2Type" InstanceCount="[Service2_InstanceCount]">
<SingletonPartition />
</StatelessService>
</Service>
</DefaultServices>
</ApplicationManifest>
因此,这有效地产生了 2 个进程,并且每个进程的激活上下文都列出了两种默认服务类型(我原本希望只有一种具有这种配置)。
欢迎任何建议(关于如何在单个 exe 中配置多种服务类型)或澄清。
【问题讨论】:
-
您真的要这样做吗?几个月前我曾想过自己这样做,但后来想起了微服务和单一职责,所以现在每个服务都进入了它自己的可执行文件。