将 Azure Service Fabric 服务映射到特定节点类型

Mapping Azure Service Fabric services to a certain node type

在 Service Fabric 应用程序 VS 模板中创建服务(或 Reliable Actors 中的参与者)毫不费力。在 Azure 门户中定义节点类型也很容易。但是如何在特定节点类型上将 service/actor 映射到 运行?

您可以使用放置约束来做到这一点。

可以在 this 文章的 "Placement constraints and node properties" 部分找到更多相关信息。

简而言之,您需要在集群上设置放置属性,然后使用 StatefulServiceDescription.PlacementConstraints.

在服务上设置放置约束

这是在 ApplicationManifest.xml 中的声明方式:

<ServiceTypes>
  <StatelessServiceType ServiceTypeName="Stateless1">
    <PlacementConstraints>(NodeTypeName==BackEnd)</PlacementConstraints>
  </StatelessServiceType>
</ServiceTypes>

并且可以通过参数在不同的环境下使用不同的约束:

<Service Name="Stateless1">
  <StatelessService ServiceTypeName="Stateless1Type" InstanceCount="[Stateless1_InstanceCount]">
    <SingletonPartition />
    <PlacementConstraints>[Stateless1_PlacementConstraints]</PlacementConstraints>
  </StatelessService>
</Service>

Stateless1_PlacementConstraints 可以在应用程序参数文件中重新定义(Cloud.xml、Local5Node.xml 等)。

更多详情: https://brentdacodemonkey.wordpress.com/2016/09/11/placement-constraints-with-service-fabric/