简体   繁体   English

Service Fabric中无状态服务的服务解析器

[英]Service Resolver for Stateless Services in Service Fabric

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? Service Fabric是否受到限制?或者我是否误解了应如何使用无状态服务? 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. 我正在构建一个Api网关。 The Api Gateway is comprised of RegistryService and a RoutingService. Api网关由RegistryService和RoutingService组成。

I have multiple service fabric applications, some of which have "front-end" stateless services which use WebApi and Owin. 我有多个服务结构应用程序,其中一些具有使用WebApi和Owin的“前端”无状态服务。 On startup these services register their routes to the RegistryService. 在启动时,这些服务将其路由注册到RegistryService。

The Gateway uses the Registryservices to determine the service to direct the request to. 网关使用Registryservices确定将请求定向到的服务。 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 任何想法都将非常有帮助

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

So for anyone else who comes along here. 因此,对于任何其他来这里的人。 Seems like it was a non issue. 似乎这不是问题。 Resetting the SF cluster fixed it. 重置SF群集可修复它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM