Service Fabric: it is several kinds of services allowed in ServiceManifest.xml

I am trying to register multiple care services in one exe (ServiceRuntime.RegisterServiceAsync). Is it supported? If so, how do I configure them?

For example: ServiceManifest.xml supports several elements StatelessServiceType in ServiceTypes:

<?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 and does not support multiple elements in StatelessService DefaultServices / Service:

 <?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> " xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" ApplicationTypeName = "EchoServiceType" ApplicationTypeVersion = " <?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> = " <?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> = " <?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> = "1.0.0" /> <?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> = "[Service2_InstanceCount]"> <?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> 

Therefore, it effectively creates 2 process, and each process "context-context" has both standard types of services listed (I would expect only one with this configuration).

Any suggestions (on how to configure several types of services within a single exe) or clarification.

+5
source share
1 answer

Refusal by the default service for the second.

Yes, you get several types of services for sharing the host process. You can see 2 of the process, because the Service Fabric places these two service instances on different nodes, and each of them need a host process. Try creating each service using an instance of InstanceCount = "- 1" to see two types of host sharing processes.

OK, return to the default services. It is inherently confusing because a manifesto manifesto applications and service manifesto intended only to describe the type of information, not information about the instance. But to create a default service instances when an instance of the application you need to specify declaratively instances and their parameters. So, what you see in the default services in your example, the same XML-equivalent of:

 PS > New-ServiceFabricService -Stateless -PartitionSchemeSingleton -InstanceCount 1 -ApplicationName fabric:/EchoService -ServiceName fabric:/EchoService/MyService1 -ServiceTypeName Service1Type PS > New-ServiceFabricService -Stateless -PartitionSchemeSingleton -InstanceCount 1 -ApplicationName fabric:/EchoService -ServiceName fabric:/EchoService/MyService2 -ServiceTypeName Service2Type 

Therefore, it makes no sense to have more than one element in StatelessService Service item because you specify the service instances that you want to create, and the type and version of the service instance.

And just for posterity is the registration code that comes with the manifesto published by the service:

 internal static class Program { private static void Main() { try { ServiceRuntime.RegisterServiceAsync("Service1Type", context => new Stateless1(context)).GetAwaiter().GetResult(); ServiceRuntime.RegisterServiceAsync("Service2Type", context => new Stateless2(context)).GetAwaiter().GetResult(); Thread.Sleep(Timeout.Infinite); } catch (Exception e) { ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString()); throw; } } } } ) GetAwaiter () GetResult ()..; internal static class Program { private static void Main() { try { ServiceRuntime.RegisterServiceAsync("Service1Type", context => new Stateless1(context)).GetAwaiter().GetResult(); ServiceRuntime.RegisterServiceAsync("Service2Type", context => new Stateless2(context)).GetAwaiter().GetResult(); Thread.Sleep(Timeout.Infinite); } catch (Exception e) { ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString()); throw; } } } } 
+8
source

All Articles