1
votes

I seem to keep getting "Service Not Found" whenever I try to resolve an endpoint for a stateless service. I have tried using the service partition resolver and also the service proxy but they both yield same results. Is there a restriction on Service Fabric or am I misunderstanding how stateless services should be used? I could not find any documentation stating either way.

To give more detail on what I am attempting to do. I am building an Api Gateway. The Api Gateway is comprised of RegistryService and a RoutingService.

I have multiple service fabric applications, some of which have "front-end" stateless services which use WebApi and Owin. On startup these services register their routes to the RegistryService.

The Gateway uses the Registryservices to determine the service to direct the request to. At which point I am trying to resolve the endpoint of said services but fail to do so. If however I change my routing to stateful backend services it works fine.

Any thoughts would be very helpful

2
First thing to check is that you're using the right service name (fabric:/yourapp/yourservice). Second thing is the partition type. Stateless services are usually created with a Singleton partitioning scheme, so make sure that ResolveAsync() is asking for the same partitioning scheme. The fact that you say it works when you switch to a stateful service makes me think you're passing in an Int64 partition key when you call ResolveAsync.Vaclav Turecek
Thanks @VaclavTurecek. I have a case statement in my assigns singleton for stateless and the int64 partition key for stateful services. and I am have checked and rechecked so many things over the last 2 days. Rewrite the middleware in 3/4 different ways.Shahzad Ahmad
I am using the default resolver. Does that matter?Shahzad Ahmad

2 Answers

9
votes

You can run this code to discover all endpoints of services running inside your cluster. Using this, you can find out how to talk to your service, by finding out the name and partition strategy of the service.

            var resolver = ServicePartitionResolver.GetDefault();
            var fabricClient = new FabricClient();
            var apps = fabricClient.QueryManager.GetApplicationListAsync().Result;
            foreach (var app in apps)
            {
                Console.WriteLine($"Discovered application:'{app.ApplicationName}");

                var services = fabricClient.QueryManager.GetServiceListAsync(app.ApplicationName).Result;
                foreach (var service in services)
                {
                    Console.WriteLine($"Discovered Service:'{service.ServiceName}");

                    var partitions = fabricClient.QueryManager.GetPartitionListAsync(service.ServiceName).Result;
                    foreach (var partition in partitions)
                    {
                        Console.WriteLine($"Discovered Service Partition:'{partition.PartitionInformation.Kind} {partition.PartitionInformation.Id}");


                        ServicePartitionKey key;
                        switch (partition.PartitionInformation.Kind)
                        {
                            case ServicePartitionKind.Singleton:
                                key = ServicePartitionKey.Singleton;
                                break;
                            case ServicePartitionKind.Int64Range:
                                var longKey = (Int64RangePartitionInformation)partition.PartitionInformation;
                                key = new ServicePartitionKey(longKey.LowKey);
                                break;
                            case ServicePartitionKind.Named:
                                var namedKey = (NamedPartitionInformation)partition.PartitionInformation;
                                key = new ServicePartitionKey(namedKey.Name);
                                break;
                            default:
                                throw new ArgumentOutOfRangeException("partition.PartitionInformation.Kind");
                        }
                        var resolved = resolver.ResolveAsync(service.ServiceName, key, CancellationToken.None).Result;
                        foreach (var endpoint in resolved.Endpoints)
                        {
                            Console.WriteLine($"Discovered Service Endpoint:'{endpoint.Address}");
                        }
                    }
                }
0
votes

So for anyone else who comes along here. Seems like it was a non issue. Resetting the SF cluster fixed it.