如何在 Azure 服务结构中的 2 node.js 个微服务之间建立通信?

How to set up a communication between 2 node.js microservices in an Azure service fabric?

我正计划设置一个 Azure 服务结构,想知道如何设置一个服务以将一些数据发送到另一个微服务。我有一个 .net 核心微服务和许多节点微服务。如果我使用来宾可执行文件来设置我的节点服务,是否可以通过任何方式在这些服务之间进行通信?

您可以 specify endpoints 来宾可执行文件:

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 中,您可以配置 Endpoints 部分:

<Endpoints>
    <Endpoint Name="NodeAppTypeEndpoint" Protocol="http" Port="3000" Type="Input" />
</Endpoints>

使用它,您可以将来宾可执行服务端点映射到您的节点服务侦听的同一端口。确保每个节点服务在唯一端口上侦听。

相同的 Endpoints 配置部分适用于您的 .net 无状态服务 ServiceManifest.xml

现在您已经有了每个服务的地址,您可以使用适合目标服务 RPC 框架的客户端进行通信。