6
votes

Creating services (or actors in the case of Reliable Actors) in the Service Fabric application VS template is effortless. Defining node types in the Azure portal is also easy. But how do you map a service/actor to run on a specific node type?

2

2 Answers

5
votes

You can do that using placement constraints.

More information on that can be found in the "Placement constraints and node properties" section of this article.

In short, you'd need to set placement properties on your cluster and then set placement constraints on the service using StatefulServiceDescription.PlacementConstraints.

2
votes

Here is declarative way to do it in ApplicationManifest.xml:

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

And you can use parameters to use different constraints in different environments:

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

Stateless1_PlacementConstraints can be redefined in application parameters files (Cloud.xml, Local5Node.xml etc).

More details: https://brentdacodemonkey.wordpress.com/2016/09/11/placement-constraints-with-service-fabric/