如何将元数据添加到Node.js grpc调用 [英] How to add metadata to nodejs grpc call
问题描述
我想知道如何将元数据添加到nodejs grpc函数调用中.在与客户建立联系时,我可以使用频道凭据
I'd like to know how to add metadata to a nodejs grpc function call. I can use channel credentials when making the client with
var client = new proto.Document('some.address:8000',
grpc.credentials.createInsecure()
)
使用client.Send(doc, callback)
时发送,但是go grpc服务器在呼叫元数据中查找我必须设置的标识信息.我尝试将grpc.credentials.combineChannelCredentials
与不安全的连接和grpc.Metadata
实例一起使用,但找不到正确的方法.
Which are send when using client.Send(doc, callback)
, but the go grpc server looks in the call metadata for identification information which I have to set. I tried using grpc.credentials.combineChannelCredentials
with the insecure connection and a grpc.Metadata
instance but I can't find the right way to do it.
我遇到的错误是TypeError: compose's first argument must be a CallCredentials object
.我试图跟进它,但是它陷入了使我迷失的C代码中,我看不到必须提供comebineChannelCredentials
的javascript类型来实现我想要的功能,并且文档在如何实现方面有些稀疏实现这一目标.
The error I run into is TypeError: compose's first argument must be a CallCredentials object
. I tried to follow it down but it goes into c code which loses me, I can't see what javascript type I have to give to comebineChannelCredentials
to achieve what I'm looking for and the docs are a little sparse on how to achieve this.
推荐答案
您可以将元数据作为可选参数直接传递给方法调用.因此,例如,您可以执行以下操作:
You can pass metadata directly as an optional argument to a method call. So, for example, you could do this:
var meta = new grpc.Metadata();
meta.add('key', 'value');
client.send(doc, meta, callback);
这篇关于如何将元数据添加到Node.js grpc调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!