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

时间:2019-03-20 15:59:46

标签: azure-service-fabric

我试图了解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);

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

1 个答案:

答案 0 :(得分:1)

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

一旦分配,它们将在服务过程中作为环境变量创建,例如:Fabric_Endpoint_<EndpointName> : port

创建侦听器时,它们负责打开端口(通常使用通过端点分配的端口),但并不能阻止您创建自定义侦听器以打开任何端口(如果具有足够的权限运行)

CreateServiceRemotingListener(context)创建默认的侦听器

EndpointResourceName设置告诉侦听器使用哪个端点(如果未定义),DefaultEndpointResourceName设置用作默认端点,默认值为“ ServiceEndpoint”

我现在不确定要回答的是:如果未找到EndpointResourceName,它将使用DefaultEndpointResourceName,我认为是,需要检查代码以确认这一点。

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