Re: [grpc-io] Sending headers on every message with bidirectional streaming?

2017-09-28 Thread 'Kun Zhang' via grpc.io
Sounds like you can just write a ServerInterceptor (which holds the Metrics 
object) to intercept ServerCall.Listener.onMessage() and 
ServerCall.Listener.onComplete()/onCancel() and do the stuff. I doesn't 
seem to involve Context (assuming you meant io.grpc.Context).

On Monday, September 25, 2017 at 3:30:59 PM UTC-7, thas@gmail.com wrote:
>
> Follow up question:
>
> In the same given scenario above, is it possible to have different 
> Contexts per message? The use case is that I'd like to have a metrics and 
> logging utility class on my server that is used to generate graphs and data 
> distributions using each call as a data point. So I'd like to pass around 
> this Metrics object across each call to do some unit of work on using its 
> member functions. 
>
>
> On Friday, September 22, 2017 at 11:56:16 AM UTC-7, thas@gmail.com 
> wrote:
>>
>> Ahh I see! Thank you very much
>>
>> On Friday, September 22, 2017 at 11:43:50 AM UTC-7, Josh Humphries wrote:
>>>
>>> Headers are per stream, not per message. The whole stream is a single 
>>> HTTP round-trip. So the first thing the server sends back are response 
>>> headers. Then the response payload (which consists of zero or more 
>>> messages). Finally, you get trailers.
>>>
>>> To include metadata for each response message, you'll have to encode 
>>> that into your RPC schema -- e.g. add a map field to your 
>>> response message (or whatever suits your need, the less stringly-typed 
>>> likely the better). Then your server can stuff that metadata into each 
>>> response message.
>>>
>>>
>>> 
>>> *Josh Humphries*
>>> jh...@bluegosling.com
>>>
>>> On Fri, Sep 22, 2017 at 2:36 PM,  wrote:
>>>

 So to send header metadata with on each call we can use interceptors. 
 Ex:
 https://github.com/grpc/grpc-java/blob/166108a9438c22d06eb3b371b5ad34a75e14787c/examples/src/main/java/io/grpc/examples/header/HeaderClientInterceptor.java

 However, for bidirectional streaming case for a given stub/channel, the 
 headers will only be sent once (via start() call). Is there a way to have 
 every message after to also have the headers sent? 

 I see that there is a sendMessage 
 https://github.com/grpc/grpc-java/blob/166108a9438c22d06eb3b371b5ad34a75e14787c/core/src/main/java/io/grpc/ServerCall.java#L128
  
 call, but it only takes in the request message as a parameter. So i'm 
 wondering if there's a way to send other parameters in the header on each 
 subsequent message call in the stream. 

 Of course, I could add the parameters to the message body, but that 
 could lead to a pretty large .proto definition. 

 Thanks!

 -- 
 You received this message because you are subscribed to the Google 
 Groups "grpc.io" group.
 To unsubscribe from this group and stop receiving emails from it, send 
 an email to grpc-io+u...@googlegroups.com.
 To post to this group, send email to grp...@googlegroups.com.
 Visit this group at https://groups.google.com/group/grpc-io.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/grpc-io/32099406-cbbb-4e43-9821-9128faa34205%40googlegroups.com
  
 
 .
 For more options, visit https://groups.google.com/d/optout.

>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to grpc-io+unsubscr...@googlegroups.com.
To post to this group, send email to grpc-io@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/c0d56a48-828d-4d60-ab97-d52e19ca1f8e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [grpc-io] Sending headers on every message with bidirectional streaming?

2017-09-25 Thread thas . himal
Follow up question:

In the same given scenario above, is it possible to have different Contexts 
per message? The use case is that I'd like to have a metrics and logging 
utility class on my server that is used to generate graphs and data 
distributions using each call as a data point. So I'd like to pass around 
this Metrics object across each call to do some unit of work on using its 
member functions. 


On Friday, September 22, 2017 at 11:56:16 AM UTC-7, thas@gmail.com 
wrote:
>
> Ahh I see! Thank you very much
>
> On Friday, September 22, 2017 at 11:43:50 AM UTC-7, Josh Humphries wrote:
>>
>> Headers are per stream, not per message. The whole stream is a single 
>> HTTP round-trip. So the first thing the server sends back are response 
>> headers. Then the response payload (which consists of zero or more 
>> messages). Finally, you get trailers.
>>
>> To include metadata for each response message, you'll have to encode that 
>> into your RPC schema -- e.g. add a map field to your 
>> response message (or whatever suits your need, the less stringly-typed 
>> likely the better). Then your server can stuff that metadata into each 
>> response message.
>>
>>
>> 
>> *Josh Humphries*
>> jh...@bluegosling.com
>>
>> On Fri, Sep 22, 2017 at 2:36 PM,  wrote:
>>
>>>
>>> So to send header metadata with on each call we can use interceptors. Ex:
>>> https://github.com/grpc/grpc-java/blob/166108a9438c22d06eb3b371b5ad34a75e14787c/examples/src/main/java/io/grpc/examples/header/HeaderClientInterceptor.java
>>>
>>> However, for bidirectional streaming case for a given stub/channel, the 
>>> headers will only be sent once (via start() call). Is there a way to have 
>>> every message after to also have the headers sent? 
>>>
>>> I see that there is a sendMessage 
>>> https://github.com/grpc/grpc-java/blob/166108a9438c22d06eb3b371b5ad34a75e14787c/core/src/main/java/io/grpc/ServerCall.java#L128
>>>  
>>> call, but it only takes in the request message as a parameter. So i'm 
>>> wondering if there's a way to send other parameters in the header on each 
>>> subsequent message call in the stream. 
>>>
>>> Of course, I could add the parameters to the message body, but that 
>>> could lead to a pretty large .proto definition. 
>>>
>>> Thanks!
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "grpc.io" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to grpc-io+u...@googlegroups.com.
>>> To post to this group, send email to grp...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/grpc-io.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/grpc-io/32099406-cbbb-4e43-9821-9128faa34205%40googlegroups.com
>>>  
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to grpc-io+unsubscr...@googlegroups.com.
To post to this group, send email to grpc-io@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/0628f727-d5bd-4349-ba34-4b1fd32a2826%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [grpc-io] Sending headers on every message with bidirectional streaming?

2017-09-22 Thread thas . himal
Ahh I see! Thank you very much

On Friday, September 22, 2017 at 11:43:50 AM UTC-7, Josh Humphries wrote:
>
> Headers are per stream, not per message. The whole stream is a single HTTP 
> round-trip. So the first thing the server sends back are response headers. 
> Then the response payload (which consists of zero or more messages). 
> Finally, you get trailers.
>
> To include metadata for each response message, you'll have to encode that 
> into your RPC schema -- e.g. add a map field to your 
> response message (or whatever suits your need, the less stringly-typed 
> likely the better). Then your server can stuff that metadata into each 
> response message.
>
>
> 
> *Josh Humphries*
> jh...@bluegosling.com 
>
> On Fri, Sep 22, 2017 at 2:36 PM,  wrote:
>
>>
>> So to send header metadata with on each call we can use interceptors. Ex:
>> https://github.com/grpc/grpc-java/blob/166108a9438c22d06eb3b371b5ad34a75e14787c/examples/src/main/java/io/grpc/examples/header/HeaderClientInterceptor.java
>>
>> However, for bidirectional streaming case for a given stub/channel, the 
>> headers will only be sent once (via start() call). Is there a way to have 
>> every message after to also have the headers sent? 
>>
>> I see that there is a sendMessage 
>> https://github.com/grpc/grpc-java/blob/166108a9438c22d06eb3b371b5ad34a75e14787c/core/src/main/java/io/grpc/ServerCall.java#L128
>>  
>> call, but it only takes in the request message as a parameter. So i'm 
>> wondering if there's a way to send other parameters in the header on each 
>> subsequent message call in the stream. 
>>
>> Of course, I could add the parameters to the message body, but that could 
>> lead to a pretty large .proto definition. 
>>
>> Thanks!
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "grpc.io" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to grpc-io+u...@googlegroups.com .
>> To post to this group, send email to grp...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/grpc-io.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/grpc-io/32099406-cbbb-4e43-9821-9128faa34205%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to grpc-io+unsubscr...@googlegroups.com.
To post to this group, send email to grpc-io@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/3188c3e1-7da2-4591-b48e-29d83b26f1dd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [grpc-io] Sending headers on every message with bidirectional streaming?

2017-09-22 Thread Josh Humphries
Headers are per stream, not per message. The whole stream is a single HTTP
round-trip. So the first thing the server sends back are response headers.
Then the response payload (which consists of zero or more messages).
Finally, you get trailers.

To include metadata for each response message, you'll have to encode that
into your RPC schema -- e.g. add a map field to your
response message (or whatever suits your need, the less stringly-typed
likely the better). Then your server can stuff that metadata into each
response message.



*Josh Humphries*
jh...@bluegosling.com

On Fri, Sep 22, 2017 at 2:36 PM,  wrote:

>
> So to send header metadata with on each call we can use interceptors. Ex:
> https://github.com/grpc/grpc-java/blob/166108a9438c22d06eb3b371b5ad34
> a75e14787c/examples/src/main/java/io/grpc/examples/header/
> HeaderClientInterceptor.java
>
> However, for bidirectional streaming case for a given stub/channel, the
> headers will only be sent once (via start() call). Is there a way to have
> every message after to also have the headers sent?
>
> I see that there is a sendMessage https://github.com/grpc/grpc-java/blob/
> 166108a9438c22d06eb3b371b5ad34a75e14787c/core/src/main/java/
> io/grpc/ServerCall.java#L128 call, but it only takes in the request
> message as a parameter. So i'm wondering if there's a way to send other
> parameters in the header on each subsequent message call in the stream.
>
> Of course, I could add the parameters to the message body, but that could
> lead to a pretty large .proto definition.
>
> Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups "
> grpc.io" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to grpc-io+unsubscr...@googlegroups.com.
> To post to this group, send email to grpc-io@googlegroups.com.
> Visit this group at https://groups.google.com/group/grpc-io.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/grpc-io/32099406-cbbb-4e43-9821-9128faa34205%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to grpc-io+unsubscr...@googlegroups.com.
To post to this group, send email to grpc-io@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/CAO78j%2BKi7%3D8QWS9o4X0qPgRab10%3Dt-z6gtidmLVnqQ-n%2BuHV7g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.