Service Fabric - 服务远程处理是否需要端点定义?

Service Fabric - Are Endpoint definitions required for service remoting?

我试图了解在哪些情况下 ServiceManifest 中需要端点定义。我有一个有状态服务,其中定义了多个服务远程侦听器。我的实现 CreateServiceReplicaListeners:

        protected override IEnumerable<ServiceReplicaListener> CreateServiceReplicaListeners()
        {
            return new[]
            {
                new ServiceReplicaListener(context => this.CreateServiceRemotingListener(context)),
                new ServiceReplicaListener(context =>
                                           {
                                               return new FabricTransportServiceRemotingListener(context,
                                                                                                 new CustomService<string>(),
                                                                                                 new FabricTransportRemotingListenerSettings
                                                                                                 {
                                                                                                     EndpointResourceName = "ustdfdomgfasdf"
                                                                                                 });
                                           }, name: "CustomListener")
            };
        }

自定义侦听器的终结点资源名称是垃圾。我没有在服务清单的资源中定义该端点:

<Resources>
    <Endpoints>
      <Endpoint Name="ServiceEndpoint" />
      <Endpoint Name="ReplicatorEndpoint" />
    </Endpoints>
  </Resources>

然而,在测试中我发现我仍然能够获得 CustomListener:

的代理
InventoryItem i = new InventoryItem(description, price, number, reorderThreshold, max);

var applicationInstance = FabricRuntime.GetActivationContext().ApplicationName.Replace("fabric:/", String.Empty);            
var inventoryServiceUri = new Uri("fabric:/" + applicationInstance + "/" + InventoryServiceName);

//Doesn't fail
ICustomService customServiceClient = ServiceProxy.Create<ICustomService>(inventoryServiceUri, 
    i.Id.GetPartitionKey(), 
    listenerName: "CustomListener");

//Still doesn't fail
var added = await customServiceClient.Add(1, 2);

对我来说,这表明只要端点和侦听器名称是唯一的,服务远程处理就不需要端点定义。是这样吗?如果不是,为什么我的示例有效?

Endpoints 需要告诉服务结构在节点中为正在该节点上启动的服务分配端口,这将防止许多服务在节点中打开端口时发生端口冲突节点。

分配后,这些将在服务进程中创建为环境变量,例如:Fabric_Endpoint_<EndpointName> : port

当您创建监听器时,他们负责打开端口,通常使用通过端点分配的端口,但不会阻止您创建自定义监听器以打开任何端口(如果 运行 有足够的权限来做所以)

CreateServiceRemotingListener(context) 创建默认侦听器

EndpointResourceName设置告诉监听器使用哪个端点,如果没有定义,DefaultEndpointResourceName设置作为默认端点,默认值为"ServiceEndpoint"

我现在不确定回答的是:如果 EndpointResourceName 没有找到,它使用 DefaultEndpointResourceName,我假设是这样,需要检查代码来确认。

当多个侦听器使用同一个端口时,它们通常有一个路径来标识每个侦听器,例如:tcp://127.0.0.1:1234/endpointpath