如何在 spring-boot 中管理 gRPC 服务器通道

How to manage gRPC server channel within a spring-boot

我有一个包含 spring-boot 应用程序和 gRPC 服务器的设置。 gRPC 服务器已经用 NodeJS 编写并部署在单独的服务器中。在我的 spring-boot 应用程序中,有一个端点接受请求对象并将其委托给 gRPC 服务器。

问题:

1) 在这种情况下,我是否需要为每个传入的 http 请求创建 rGPC 通道? (听起来效率不高)

2) 还是我在 spring-boot 应用程序初始化时创建了一个通道?

在2)方案中,当gRPC服务器宕机需要从eureka服务器获取新的URI时,如何管理?

这里是 gRPC channel creation in spring-boot.

2) 是要走的路。为了解决服务器宕机问题,您可以在将传入的 http 请求转发到 gRPC 服务器之前检查通道状态 (io.grpc.ManagedChannel.getState(boolean)),如果不是 READY,则在适当重构后调用您的 initCommunicationChannel()这样它就可以被多次调用。

或者,您可以实施名称解析器插件 (https://github.com/grpc/grpc/blob/master/doc/naming.md) which simply calls eurekaClient.getApplication("logger-app").getInstances() to return resolved addresses which are then used by a client side load balancing policy (https://github.com/grpc/grpc/blob/master/doc/load-balancing.md)。