node.js - 有没有办法为 grpc-node 客户端配置生成方法名称?

标签 node.js microservices grpc

我希望使用 grpc-node 客户端与使用 go-micro 框架在 Go 中构建的微服务进行通信。我遇到了一个问题,其中 go-micro 使用句点 (.) 定义方法名称来分隔命名空间和方法名称,而 grpc-node 斜杠 (/)。无论如何,是否可以配置此模式以使这两个进程相互通信?

最佳答案

gRPC over HTTP/2 protocol documentation定义路径构造如下:

Path → ":path" "/" Service-Name "/" {method name}

附上此附加说明

Some gRPC implementations may allow the Path format shown above to be overridden, but this functionality is strongly discouraged. gRPC does not go out of its way to break users that are using this kind of override, but we do not actively support it, and some functionality (e.g., service config support) will not work when the path is not of the form shown above.

因此,Node gRPC 客户端遵循规范,并且 go-micro 使用的替代格式似乎是硬编码在其代码生成插件 ( here ) 中。我认为这是一个错误。

话虽如此,有一个可行的解决方法可以匹配 Node gRPC 库中的方法名称格式。当您在 Node 中加载 .proto 文件时,每个客户端构造函数都有一个 service 成员,它是描述服务的纯 JavaScript 对象。它是方法名称到方法定义的映射,每个方法定义都包含一个 path 成员。您可以修改每个方法的路径以匹配 go-micro 使用的模式,然后将生成的服务对象传递给 grpc.makeGenericClientConstructor 以获得连接到修改后的服务的新客户端构造函数。

关于node.js - 有没有办法为 grpc-node 客户端配置生成方法名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49308482/

相关文章:

node.js - 在哪里可以找到 Node fs 包的 fs.Stats 对象中的每个变量是什么?

node.js - 如何使用 Node 运行后端服务器?

angularjs - *** process.env.ENV未定义,假设env为 'prod'

c++ - 如何在 C++ 中取消对 grpc::ClientReader 的 Read() 调用?

protocol-buffers - GRPC 服务发现

node.js - 使用 Node js 在 nodejitsu 中运行转发代理服务器

android - 在 Android 设备上的 google chrome 浏览器上从 node.js 服务器下载文件的错误

architecture - 两种微服务可读写一个数据库表

spring-boot - Spring Cloud Config 如何下载服务的远程配置?

c++ - 在 GRPC 中使用字节数组 (cpp)