Search code examples
c#azureazure-service-fabric

How can I discover what kind of endpoints a service offers with ServicePartitionResolver?


I am trying to write a service resolver and for that I am currently using, as mentioned in https://learn.microsoft.com/en-us/azure/service-fabric/service-fabric-reliable-services-communication, the ServicePartitionResolver.

This all works fairly well so far. Given my service information, I am able to resolve a service like this:

var resolvedService = await ServicePartitionResolver.GetDefault().ResolveAsync(service.ServiceName, key, CancellationToken.None);

Now, in order to allow my services to communicate with each other, I am reading the endpoint address like this for the first one e.g.:

resolvedService.Endpoints.First().Address

This properly returns the required endpoint I returned in the OpenAsync method of my ICommunicationListener implementation.

Basically, this is all doing a fine job as long as the protocol is http.

As soon as I switch the protocol to something like for example tcp in my ServiceManifest.xml of the service where the request should go to:

<Endpoints>
  <!-- This endpoint is used by the communication listener to obtain the port on which to 
       listen. Please note that if your service is partitioned, this port is shared with 
       replicas of different partitions that are placed in your code. -->
  <Endpoint Protocol="tcp" Name="ServiceEndpoint" Type="Input" Port="3245" />
</Endpoints>

The ServiceResolver still resolves my endpoint to an address starting with http.

So, now my question - Am I simply doing something wrong? Because to me it seems like I can't really know what endpoint I am dealing with exactly. Even if this is not directly reflected in the Address, I could still just trim the http part from the endpoint string, but there is no information what kind of endpoint it is as well. So, technically, I can replace the http:// with blank, but it would be preferable to do this based on something I get back from Service Fabric instead of "because I know about the endpoint".

Any ideas?


Solution

  • The protocol definition from the manifest is not used define the endpoint. The communication listener implementation returns the endpoint from OpenAsync. So I'd recommend starting the search in there.

    More info here and here.