https://kotlinlang.org logo
#grpc
Title
# grpc
t

taer

06/24/2022, 9:38 PM
I did the threadlocal version. I added an AtmonicReference<String> as a threadLocal/contextElement. In the stubb, I get the Threadlocal and set the value. In the interceptor, I get the threadLocal then get the value and set it. But.. That's a lot of pain, and I'm not even sure the "post interceptor" is even running on the same thread after the "stub service method" runs.
m

Minsoo Cheong

06/27/2022, 6:53 AM
So you're trying to get the client-sent metadata from within the server-side gRPC stub correct? I've seen many examples that use io.grpc.Context to store the metadata which uses the methods you listed ( ThreadLocal or CoroutineContext ) to transfer the context according to which stub you use (coroutine or not) If you use this, you won't have to implement the ThreadLocal approach yourself. There are also other options like using a framework that does the same thing to provide Request Context (like armeria) but I think io.grpc.Context + Interceptors is what you were looking for examples: https://www.tabnine.com/code/java/classes/io.grpc.Contexts
** I'm not 100% sure about the internals though since I didn't go through it myself 😅
t

taer

06/30/2022, 9:14 PM
Late response. What I wanted to do is in server code, send trailers.
🥲 1
7 Views