Ryan is right in with the idea. Nevertheless, the server side interceptor
piece doesn't exist in C#, so for now you need to extract the header in the
server-side handler manually (and add it directly to the child call or to a
custom call invoker.

Also, you need to be very careful about choosing the right context type, as
just "thread local" context won't work with async/await.

On Sun, Feb 26, 2017 at 8:02 AM, Ryan Michela <[email protected]> wrote:

> I've done this using grpc-java. The theory should be similar for C#.
>

> You need to use a custom header to propagate your correlation id over the
> wire. You will also need a place to store the correlation id between
> processing a service call and calling the next service in the chain, such
> as a thread local variable.
>
> On the client side use an InterceptingCallInvoker to marshal the thread
> local correlation id into a header. On the server side, use a
> InterceptingCallInvoker to marshal the header into the thread local
> variable. Using this pattern you can chain multiple service calls while
> transparently preserving a single correlation id across the entire chain.
> This is called the Ambient Context pattern.
>
> A three service chain would look something like this:
> Thread local -> Header -> Thread local -> Header -> Thread Local
>
> If you are using asynchronous APIs you will have to do extra work to make
> sure your thread local context survives the thread hopping that happens
> with async/await.
>

> On Tuesday, February 21, 2017 at 2:22:38 AM UTC-8, [email protected]
> wrote:
>>
>>
>> I have many microservices en .net communicating with each other via gRPC
>> (I use "protoc.exe" and "grpc_csharp_plugin.exe" to generate the client and
>> server parts).
>> Now I need that the gRPC request keeps the same correlationId passing
>> through different microservices.
>>
>> Please advise if I can add my own gRPC plugin that handle this
>> automatically?
>>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> 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/82238ec1-2404-49c0-b78a-dc1faeba973e%40googlegroups.com
> <https://groups.google.com/d/msgid/grpc-io/82238ec1-2404-49c0-b78a-dc1faeba973e%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> 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 [email protected].
To post to this group, send email to [email protected].
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/CACF4M0SOjdnW2P%2Bvhveg%3DxAQ5i0s9f8LLbcvp_ohmhQ3aHmnaA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to