服务结构命名服务未转发到分配给Guest Executable的终结点 [英] Service Fabric Naming Service not forwarding to endpoint assigned to Guest Executable

查看:50
本文介绍了服务结构命名服务未转发到分配给Guest Executable的终结点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已按照以下指南设置了具有两项服务的应用程序,一项是标准的aspnet核心api,另一项是节点快速应用程序:

I have setup an application with two services, one a standard aspnet core api, and another node express app by following the guide here:

https://docs .microsoft.com/en-us/azure/service-fabric/service-fabric-deploy-existing-app

当我在本地部署应用程序时,我可以使用命名服务来访问AspNetCore应用程序,例如:

When I deploy the application locally I can use the naming service to hit the AspNetCore application such as:

http://localhost:19081/sf_node_test_02/AspNetCore/api/values

同样,我希望能够使用以下地址访问我的来宾可执行文件的api:

Likewise, I expect to be able to hit the api of my guest executable using this address:

http://localhost:19081/sf_node_test_02/NodeApp

但是,这不起作用. 如果我使用服务的直接网址,例如: http://localhost:30032/我可以看到Node js应用程序实际上正在按预期运行.

However, this does not work. If I use the direct url of the service such as: http://localhost:30032/ I can see the node js app is in fact working as expected.

现在,我知道在运行AspNet核心应用程序时,它将显式地将其侦听地址发送回命名服务,但是来宾可执行文件却没有,因此可以解释为什么它们的行为可能有所不同.另外,据我了解,当前版本的服务结构无法为来宾可执行文件提供有关动态分配端口的信息,因此必须在服务端点和应用程序中对其进行硬编码,以侦听同一端口.

Now, I know when running the AspNet core application it is explicitly sending it's listening address back to the naming service but the guest executable is not so that explains why they might behave differently. Also, from what I understand the current version of service fabric does not provide the guest executable the information about a dynamically assigned port so it must be hard coded in the service endpoint and also in the application to listen on the same port.

例如如果我有:

<Endpoint Name="NodeAppTypeEndpoint" Port="30032" Protocol="http" Type="Input" UriScheme="http"/>

然后在nodejs应用中,我还必须具有:

Then in the nodejs app I must also have:

const port = process.env.PORT || 30032;
app.listen(port, () => {
    console.log(`Listening on port: ${port}`);
});

在两个地方都标有30032.

Noticed 30032 in both places.

从文档中:

此外,您可以要求Service Fabric将此端点发布到 命名服务,以便其他服务可以发现要访问的端点地址 这项服务.这使您能够在 来宾可执行文件的服务.发布的端点地址是 格式为UriScheme://IPAddressOrFQDN:Port/PathSuffix. UriScheme和 PathSuffix是可选属性. IPAddressOrFQDN是IP地址 或此可执行文件所在节点的完全限定域名 ,然后为您计算出来.

Furthermore you can ask Service Fabric to publish this endpoint to the Naming Service so other services can discover the endpoint address to this service. This enables you to be able to communicate between services that are guest executables. The published endpoint address is of the form UriScheme://IPAddressOrFQDN:Port/PathSuffix. UriScheme and PathSuffix are optional attributes. IPAddressOrFQDN is the IP address or fully qualified domain name of the node this executable gets placed on, and it is calculated for you.

我将其解释为,如果我的ServiceManifest.xml同时具有UseImplicitHost="true",则它应自动为命名服务提供由端点描述构建的网址.

I interpreted this to mean that if my ServiceManifest.xml has both UseImplicitHost="true" then it should automatically give the naming service the url constructed by the endpoint description.

http://localhost:19081/sf_node_test_02/NodeApp -> http://localhost:30032

服务结构是否会自动为命名服务提供此服务的侦听地址是否正确?

反正我需要检查命名服务中的映射吗? 这会让我知道它是否为我的节点应用程序提供了一个条目,但是它与我期望的不同,或者实际上它没有条目.

Is there anyway for me to inspect the mapping in the naming service? This would let me know if it does have an entry for my node application but it is just different than what I expect or if in fact it has no entry.

如果没有条目,那么我也不知道该访客可执行应用程序在云中部署后如何对公众可见.

If it doesn't have an entry then I don't know how this guest executable application would be visible to the public when deployed in the cloud either.

推荐答案

您可以使用FabricClient中的QueryManager列出集群中服务的注册端点.这应该显示您的节点服务是否存在端点.

You can use the QueryManager of FabricClient to list registered endpoints for services in your cluster. This should reveal if there is an endpoint for your node service.

var fabricClient = new FabricClient();
var applicationList = fabricClient.QueryManager.GetApplicationListAsync().GetAwaiter().GetResult();
foreach (var application in applicationList)
{
    var serviceList = fabricClient.QueryManager.GetServiceListAsync(application.ApplicationName).GetAwaiter().GetResult();
    foreach (var service in serviceList)
    {
        var partitionListAsync = fabricClient.QueryManager.GetPartitionListAsync(service.ServiceName).GetAwaiter().GetResult();
        foreach (var partition in partitionListAsync)
        {
            var replicas = fabricClient.QueryManager.GetReplicaListAsync(partition.PartitionInformation.Id).GetAwaiter().GetResult();
            foreach (var replica in replicas)
            {
                if (!string.IsNullOrWhiteSpace(replica.ReplicaAddress))
                {
                    var replicaAddress = JObject.Parse(replica.ReplicaAddress);
                    foreach (var endpoint in replicaAddress["Endpoints"])
                    {
                        var endpointAddress = endpoint.First().Value<string>();
                        Console.WriteLine($"{service.ServiceName} {endpointAddress} {endpointAddress}");
                    }
                }
            }
        }
    }
}

这篇关于服务结构命名服务未转发到分配给Guest Executable的终结点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆