I got a c# grpc service which can get a request to get a setting in a form of a SINGLE json string which can be very large and I don't want to send it all at once. However, the string can not be processed before it arrives completely.
I know there's an option to use the stream
keyword in the protobuf and read the string as it arrives, instead of sending it as a whole.
I have only found examples of receiving several items from a stream (with asyncServerStreamingCall.ResponseStream.MoveNext()
), However I don't know how to stream a single string.
My questions are:
Is streaming a correct approach for this situation where you need to stream only a single object (string in this case), and CANT process it before it arrives completely?
How do I stream and receive a string like that (from both server and client sides)?
Streaming in gRPC is, as you mentioned, talking about sending multiple discreet operations on a single open channel. Whether unary or streaming, individual messages in gRPC must be received and decided in their entirety - there isn't a concept of an open byte-stream. Instead, you would need to send multiple messages that each contain some fragment of the payload, presumably just in a bytes
field, and send the large payload split over some number of such messages. The receiver would need to combine them, perhaps appending to a file, or similar, if it will be inconveniently large for in-memory storage.