Coder Social home page Coder Social logo

Comments (11)

harlow avatar harlow commented on June 16, 2024 3

Here is a commit w/ an example of using metadata for anyone interested.

Works nicely for things such as traceID:
harlow/go-micro-services@221a67b

from grpc-go.

dmitshur avatar dmitshur commented on June 16, 2024 2

Please use metadata API to transmit your key-value pair. The example is
for unary rpc:
https://github.com/grpc/grpc-go/blob/master/test/end2end_test.go#L355
for streaming rpc:
https://github.com/grpc/grpc-go/blob/master/test/end2end_test.go#L504

For anyone looking for that example in the future, the above links won't work because master has since changed and the line numbers don't match up. Here are the correct links:

For unary rpc:

_, err := tc.UnaryCall(ctx, req, grpc.Header(&header), grpc.Trailer(&trailer))

For streaming rpc:

func TestMetadataStreamingRPC(t *testing.T) {

Tip: You can press y when looking at a file to get a permalink:

image

from grpc-go.

dsymonds avatar dsymonds commented on June 16, 2024

Contexts are not for passing arbitrary bits of data from client to server. That's what the RPC message itself is for. There will probably be a mechanism for attaching bits of data to an RPC via a context (e.g. trace IDs), but it's going to be tightly controlled, and almost definitely not what you want to use.

from grpc-go.

iamqizhao avatar iamqizhao commented on June 16, 2024

Please use metadata API to transmit your key-value pair. The example is
for unary rpc:
https://github.com/grpc/grpc-go/blob/master/test/end2end_test.go#L355
for streaming rpc:
https://github.com/grpc/grpc-go/blob/master/test/end2end_test.go#L504

Cancellation is propagated to server only when it is needed.

On Sun, Mar 22, 2015 at 4:43 PM, David Symonds [email protected]
wrote:

Contexts are not for passing arbitrary bits of data from client to server.
That's what the RPC message itself is for. There will probably be a
mechanism for attaching bits of data to an RPC via a context (e.g. trace
IDs), but it's going to be tightly controlled, and almost definitely not
what you want to use.


Reply to this email directly or view it on GitHub
#130 (comment).

from grpc-go.

harlow avatar harlow commented on June 16, 2024

There will probably be a mechanism for attaching bits of data to an RPC via a context (e.g. trace IDs), but it's going to be tightly controlled, and almost definitely not what you want to use.

@dsymonds any idea how far down the line this will be? It would be really nice to have Trace IDs as part of the context. It feels a bit clunky having to wrap all the Protos with Args/Req/Reply messages just to pass the Tracer around.

Update

Example of using gRPC metadata context:
https://medium.com/@harlow/grpc-context-for-client-server-metadata-91cec8729424

from grpc-go.

iamqizhao avatar iamqizhao commented on June 16, 2024

On Sat, Apr 11, 2015 at 9:15 AM, Harlow Ward [email protected]
wrote:

There will probably be a mechanism for attaching bits of data to an RPC
via a context (e.g. trace IDs), but it's going to be tightly controlled,
and almost definitely not what you want to use.

@dsymonds https://github.com/dsymonds any idea how far down the line
this will be? It would be really nice to have Trace IDs as part of the
context. It feels a bit clunky having to wrap all the Protos with
Args/Req/Reply messages just to pass the Tracer around.

grpc-go does not allow users attach metadata to the context directly (grpc
will ignore that). Users are required to use metadata API to attach the
info (e.g., trace ID) to the context.


Reply to this email directly or view it on GitHub
#130 (comment).

from grpc-go.

dramdass avatar dramdass commented on June 16, 2024

Is there a way to set the metadata from the generated protobuf client code?

from grpc-go.

iamqizhao avatar iamqizhao commented on June 16, 2024

Can you take a look at the examples in my very first reply on this issue on
how to set and receive metadata and see whether it answers your question?

Copied/pasted for your convenience:

Please use metadata API to transmit your key-value pair. The example is
*for unary rpc: *

https://github.com/grpc/grpc-go/blob/master/test/end2end_test.go#L355
https://github.com/grpc/grpc-go/blob/master/test/end2end_test.go#L355

for streaming rpc:

https://github.com/grpc/grpc-go/blob/master/test/end2end_test.go#L504
https://github.com/grpc/grpc-go/blob/master/test/end2end_test.go#L504

On Mon, Apr 27, 2015 at 10:12 AM, dramdass [email protected] wrote:

Is there a way to set the metadata from the generated protobuf client code?


Reply to this email directly or view it on GitHub
#130 (comment).

from grpc-go.

iamqizhao avatar iamqizhao commented on June 16, 2024

Thanks, Harlow!

On Fri, May 1, 2015 at 5:20 PM, Harlow Ward [email protected]
wrote:

Here is a commit for anyone interested in using the metadata. Works
nicely for things such as traceID:
harlow/go-micro-services@221a67b
harlow/go-micro-services@221a67b


Reply to this email directly or view it on GitHub
#130 (comment).

from grpc-go.

pires avatar pires commented on June 16, 2024

@harlow you rock! Thank you.

from grpc-go.

WIZARD-CXY avatar WIZARD-CXY commented on June 16, 2024

@harlow just what I need! Tnank you!

from grpc-go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.