端点在Service Fabric服务的ServiceManifest中配置什么? [英] What do the EndPoints configure in the ServiceManifest of an Service Fabric Service?
问题描述
我们有一个Service Fabric Service项目,其中包含多种服务:Actor,有状态服务和无状态服务组合到一个ServiceManifest中.
We have a Service Fabric Service project with multiple services: Actors, Stateful services and Stateless services combined into one ServiceManifest.
两个有状态服务不起作用:调用了构造函数,创建了通讯侦听器(通过远程处理),但是未调用了RunAsync方法.
Two stateful services did not work: the constructors were called, the communicationlisteners (through remoting) were created, but the RunAsync method was not called.
从ServiceManifest.xml中删除端点列表后,服务将再次开始工作.但是现在我们不知道为什么以及如何工作.有人可以解释吗?
After removing the endpoint listing from the ServiceManifest.xml the services started working again. But now we are left wondering why and how this works. Could someone explain?
为了说明这一点,相关部分是
To illustrate, the relevant section was
<Resources>
<Endpoints>
<Endpoint Name="WebServiceEndpoint" Type="Input" Protocol="http" Port="80" />
<Endpoint Name="StatelessServiceEndpoint1" Type="Input" Protocol="http" Port="10101" />
<Endpoint Name="ActorServiceEndpoint1" />
<Endpoint Name="ActorServiceReplicatorEndpoint1" />
<Endpoint Name="ActorServiceEndpoint2" />
<Endpoint Name="ActorServiceReplicatorEndpoint2" />
<Endpoint Name="ActorServiceEndpoint3" />
<Endpoint Name="ActorServiceReplicatorEndpoint3" />
<Endpoint Name="ActorServiceEndpoint4" />
<Endpoint Name="ActorServiceReplicatorEndpoint4" />
<Endpoint Name="StatefulServiceEndpoint1" Type="Input" Protocol="http" />
<Endpoint Name="StatefulServiceReplicatorEndpoint1" />
<Endpoint Name="StatefulServiceEndpoint2" Type="Input" Protocol="http" />
<Endpoint Name="StatefulServiceReplicatorEndpoint2" />
<Endpoint Name="StatelessServiceEndPoint2" Type="Input" Protocol="http" />
</Endpoints>
</Resources>
将其更改为此
<Resources>
<Endpoints>
<Endpoint Name="WebServiceEndpoint" Type="Input" Protocol="http" Port="80" />
<Endpoint Name="StatelessServiceEndpoint1" Protocol="http" />
<Endpoint Name="ActorServiceReplicatorEndpoint1" />
<Endpoint Name="ActorServiceReplicatorEndpoint2" />
<Endpoint Name="ActorServiceReplicatorEndpoint3" />
<Endpoint Name="ActorServiceReplicatorEndpoint4" />
<Endpoint Name="StatefulServiceReplicatorEndpoint1" />
<Endpoint Name="StatefulServiceReplicatorEndpoint2" />
</Endpoints>
</Resources>
一切正常.但是为什么呢?
everything worked. But why?
编辑 完整的ServiceManifest是这样的:
EDIT The complete ServiceManifest is this:
<?xml version="1.0" encoding="utf-8"?>
<ServiceManifest Name="Service" 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>
<StatefulServiceType ServiceTypeName="ActorService1Type" />
<StatefulServiceType ServiceTypeName="ActorService1Type" HasPersistedState="true" />
<StatefulServiceType ServiceTypeName="ActorService3Type" />
<StatefulServiceType ServiceTypeName="ActorService4Type" HasPersistedState="true" />
<StatefulServiceType ServiceTypeName="StatefulService1Type" HasPersistedState="true" />
<StatefulServiceType ServiceTypeName="StatefulService2Type" HasPersistedState="true" />
<StatelessServiceType ServiceTypeName="StatelessService1Type" />
<StatelessServiceType ServiceTypeName="StatelessService2Type" />
<StatelessServiceType ServiceTypeName="WebServiceType" />
</ServiceTypes>
<CodePackage Name="Code" Version="1.0.0">
<SetupEntryPoint>
<ExeHost>
<Program>Setup.exe</Program>
</ExeHost>
</SetupEntryPoint>
<EntryPoint>
<ExeHost>
<Program>Service.exe</Program>
</ExeHost>
</EntryPoint>
</CodePackage>
<ConfigPackage Name="Config" Version="1.0.0" />
<Resources>
<Endpoints>
<Endpoint Name="WebServiceEndpoint" Type="Input" Protocol="http" Port="80" />
<Endpoint Name="StatelessServiceEndpoint1" Protocol="http" />
<Endpoint Name="ActorServiceReplicatorEndpoint1" />
<Endpoint Name="ActorServiceReplicatorEndpoint2" />
<Endpoint Name="ActorServiceReplicatorEndpoint3" />
<Endpoint Name="ActorServiceReplicatorEndpoint4" />
<Endpoint Name="StatefulServiceReplicatorEndpoint1" />
<Endpoint Name="StatefulServiceReplicatorEndpoint2" />
</Endpoints>
</Resources>
</ServiceManifest>
推荐答案
由于没有具体的错误或错误消息可以解决,因此很难知道在最初报告的情况下发生了什么,但是最终这通常是端口冲突共享您不想要或无法共享的端口,或者端口耗尽.
Hard to know what happened in your initial reported case since there's no specific error or error message to work off of, but usually this is port conflicts when you end up sharing ports that you don't really want to or which can't be shared, or port exhaustion.
服务清单中的端点资源主要用于以下情况:
The endpoint resource in your service manifest is mainly for times when:
- 您希望SF帮助您为服务分配通信资源(例如端口)
- 您希望SF帮助配置这些资源:
- 分配一些端口,并将其始终分配给一组工作负载
- 在本地防火墙上打孔
- 设置URLACL(仅与Windows上通过http.sys的http相关)
- 设置和配置证书以启用安全通信(相同的警告)
- you want SF to help with allocating communication resources like ports for your services
- you want SF to help configure those resources:
- Allocating some port and consistently assigning it to some set of workloads
- Punching a hole in the local firewall
- Setting up a URLACL (relevant to http on windows through http.sys only)
- Setting up and configuring certs to enable secure communication (same caveat)
通常,如果您不需要/想要帮助,则可以随意忽略端点资源,因为SF确实希望服务代码能够完成设置.在您未真正使用SF的编程模型的情况下,端点资源更为重要,因为这是您与SF交流端点的方式.
In general you're free to ignore the endpoint resource if you don't need/want the help, since SF really is expecting the service code to do it's setup. In cases where you're not really using SF's programming models then the endpoint resource is more important since it's how you communicate to SF what your endpoints are.
您得到的行为确实取决于您使用的传输方式,操作系统的动态端口范围和您定义的应用程序端口范围以及服务代码的实际作用.
The behavior you get really depends on the transport you're using, as well as the OS's dynamic port range and the Application port range that you've defined, as well as what the service code actually does.
Let's say you're setting up an http communication listener in your service like so, and walk through a few examples of what happens when you define and endpoint in your manifest or don't.
1)假设您没有在服务清单中添加有关端点的任何内容.这意味着您实际上将端口0指定为代码.在这种情况下,SF不会进行任何分配或管理.操作系统正在从OS动态端口范围分配端口.对于每个服务实例侦听器,实际分配的端口将有所不同.在大多数情况下,这应该是一个合理的默认选择.
1) Let's say you put nothing in your service manifest about endpoints. This means that effectively you're specifying 0 as the port in code. In this case SF's not doing any allocation or management. The port is getting assigned by the OS from the OS dynamic port range. The port that actually gets assigned will be different for each service instance listener. This should work as a reasonable default choice in most scenarios.
2)假设您要在清单中指定一个端点,而根本不指定任何端口,即:
2) Let's say you're specifying an endpoint in the manifest and not specifying any port at all, i.e.:
<Endpoint Name="HealthServiceEndpoint"/>
在这种情况下,分配的端口将来自SF应用程序端口范围.对于同一进程中托管的任何服务实例,它都是相同的,但跨进程是不同的. (因此,如果您使用的是互斥或共享
In this case, the port that is assigned will come from the SF application port range. It will be the same for any service instances hosted in the same process, but different across processes. (So it matters if you are using the Exclusive or Shared process hosting model) This also presumes that reusing the port is supported for your transport. Most transports don't (like http on via Kestrel in .NET, TCP under most cases), but there are some notable examples (http.sys based http transports on Windows like WebListener/HttpSys, tcp via net.tcp in WCF probably a few others).
3)假设您要在服务结构清单中指定一个端点,并为该端口显式指定0,即:
3) Let's say you're specifying an endpoint in the service fabric manifest and explicitly specifying 0 for that port i.e.:
<Endpoint Name="HealthServiceEndpoint" Port="0" Protocol="http"/>
在这种情况下,分配的端口将来自操作系统动态端口范围,并且最终将在使用该终结点的同一进程中托管的所有服务实例相同/共享.跨进程的端口将有所不同. (因此,如果您使用的是互斥或共享进程托管模型)
In this case the port that gets assigned will be from the OS dynamic port range, and it will end up the same/shared for any service instances hosted in the same process that use that endpoint. The port will be different across processes. (So again it matters if you are using the Exclusive or Shared process hosting model)
4)自然,如果指定了端点并指定了特定端口,则该端口将用于进程内和进程间的所有服务实例.这在某种程度上隐式地假设这种共享将起作用,这又取决于您的传输和平台,或者您从未计划在该节点上运行一个以上的服务实例.
4) Naturally if the endpoint is specified and a specific port is specified, that port will be used for all service instances both within and across processes. This somewhat implicitly assumes that such sharing is going to work, which again depends on your transport and platform, or that you're never planning on running more than one instance of the service on this node.
其他琐事:
- "transport"元素主要确定SF是在Windows上的http.sys中注册您的URL还是配置证书以保护流量(这大部分可以在您的服务代码或SetupEntryPoint中完成).
- 在撰写本文时,Type类型将被忽略(这是SF的较早版本的保留)
- PathSuffix用于创建默认的uri片段,该片段会附加到平台分配的IP和端口上.在某些情况下,如果代码没有使用SF的侦听器API来在/api/value之类的不同路径上设置某些侦听器,例如容器中的代码可能会使用这种代码.
这篇关于端点在Service Fabric服务的ServiceManifest中配置什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!