connectrpc / connect-go

The Go implementation of Connect: Protobuf RPC that works.
https://connectrpc.com
Apache License 2.0
2.94k stars 96 forks source link

How do I understand sent or recieved message on streaming? #762

Closed blackmarllbor0 closed 2 months ago

blackmarllbor0 commented 3 months ago

En interceptor necesito entender si un mensaje está siendo enviado o recibido, pero realmente no he descubierto cómo. He visto tipos StreaminType, pero estos, según tengo entendido, se encargan de saber de dónde viene el mensaje, no si se envía o no. ¿Alguien sabe cómo obtener esta información?

jhump commented 3 months ago

In an interceptor I need to understand if a message is being sent or received, but I haven't really figured out how. I have seen StreamingType types, but these, as I understand it, are responsible for knowing where the message comes from, not whether it is sent or not. Does anyone know how to obtain this information?

In an interceptor, you can look at request.Spec().IsClient to see if the interceptor is called in a client (if false, the interceptor is being called in a server handler). In a client, the request message is being "sent" and the response is "received". In a server handler, it's the opposite: the request message is "received" and the response is "sent".

For the stream interceptor functions, you'll have (and can wrap) a StreamingClientConn or StreamingHandlerConn (depending on whether the interceptor is being called in a client or a server handler). These have methods named Send and Receive which make the transmission direction very clear.

blackmarllbor0 commented 3 months ago

@jhump can you please elaborate on what exactly you meant by streamin?

jhump commented 3 months ago

@jhump can you please elaborate on what exactly you meant by streamin?

When I say "stream interceptor functions", I am referring to the WrapStreamingClient and WrapStreamingHandler methods of Interceptor.