有没有一种方法可以配置grpc-node客户端的生成方法名称? [英] Is there a way to configure the generate method name for grpc-node client?

查看:176
本文介绍了有没有一种方法可以配置grpc-node客户端的生成方法名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am hoping to use a grpc-node client to talk to a microservice built in Go using the go-micro framework. I am running into an issue where go-micro defines method names using periods (.) to separate namespaces and method names, whereas grpc-node slashes (/). Is there anyway to configure this pattern to have these two processes talk to each other?

推荐答案

路径→:path""/"服务名称"/" {方法名称}

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

带有附加说明

某些gRPC实现可能允许覆盖上面显示的 Path 格式,但是强烈建议不要使用此功能. gRPC不会竭尽全力破坏正在使用这种替代的用户,但是我们并未积极地支持它,并且当路径不是上面显示的形式时,某些功能(例如,服务配置支持)将不起作用

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使用的备用格式似乎已在其代码生成插件中硬编码(

So, the Node gRPC client is following the specification, and the alternate format used by go-micro appears to be hard coded in their code generation plugin (here). I would consider that to be a bug.

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

That being said, there is a viable workaround to match that method name format in the Node gRPC library. When you load a .proto file in the Node each client constructor function has a service member which is a plain JavaScript object that describes the service. It is a map of method names to method definitions, and each method definition includes a path member. You can modify the path of each method to match the pattern that go-micro uses, then pass the resulting service object to grpc.makeGenericClientConstructor to get a new client constructor that connects to the modified service.

这篇关于有没有一种方法可以配置grpc-node客户端的生成方法名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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