Service Resolver for Stateless Services in Service Fabric

家住魔仙堡 提交于 2020-01-13 06:28:10

问题


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


回答1:


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}");
                        }
                    }
                }



回答2:


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



来源:https://stackoverflow.com/questions/40248235/service-resolver-for-stateless-services-in-service-fabric

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!