shlatchz
shlatchz

Reputation: 1652

WebApi Service pinned to one Node

I have a Stateless API Service in a Service Fabric solution, I want this service to be pinned to only one node of the two nodes that I have on my cluster.

How can I limit the API service to only live on one node? The main problem is that each node has its own URL, and if the service jumps to the other node, the users can't connect to the API.

Thanks!

Upvotes: 0

Views: 196

Answers (2)

user186876
user186876

Reputation: 59

To answer the problem you're experiencing (as per your comment above), not responding to your original question (which is not recommended behaviour), you need to solve this in the Load balancer. Add all your webapi node type ip-addresses to the "Backend pools" of your Load balancer (one per node type). Also, update your settings to deploy to multiple nodes as described above, setting instance count to -1.

Upvotes: 0

Chuck Duffy
Chuck Duffy

Reputation: 279

I am not sure where the notion that you can't have more than one stateless Web API per cluster came from, but I suspect you are thinking of the local development machine.

In a production cluster you can host dozens of stateless Web API applications per node, and they can all share the same IP and port, and they can appear as one logical API surface.

In a local development cluster you can only have one instance of a Web API per cluster on the same IP and port because it's only one physical machine (your development box).

You resolve this by using the Application Parameters and publish profiles.

The publish profile for the cloud uses the setting -1, which means run on all nodes.

ApplicationParameters\Cloud.xml - [Parameter Name="TokenExchange_InstanceCount" Value="-1" /]

The publish profile for local development uses the setting 1, which means run on one node.

ApplicationParameters\Local.xml - [Parameter Name="TokenExchange_InstanceCount" Value="1" /]

If multiple APIs share the same IP and port you will need to differentiate applications by endpoint URL - for example, by adding additional segments to the URL

_serverUrl = $"{endpoint.Protocol}://+:{endpoint.Port}/foo/bar/";

Upvotes: 3

Related Questions