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()
)
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.
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:
For sake of completeness I'm going to extend on @murgatroid99 answer.
In order to attach metadata to a message on the client you can use:
On the server side int your RPC method being called, when you want to grab your data you can use:
I eventually worked it out through introspecting the grpc credentials code and modifying the implementation to expose an inner function. In the
grpc
module in thenode_modules
, filegrpc/src/node/src/credentials.js
add the lineafter
CallCredentials
is imported. Then, in your code, you can write something likeThen use
extra_creds
in the client builderNow you can make your client