Implement streaming APIs
In Chapter 5, Synchronous Communication, we covered different types of synchronous communication and mentioned that there are client- and server-side streaming options that can be used for sending sequences of messages. So far, we haven’t used any streaming APIs in the book; however, let’s illustrate how to implement client-side streaming so you get a better picture of how to use streaming APIs in your microservices.
To demonstrate streaming, we are going to modify the movie service by adding a function that will handle streaming file uploads: a client will send a sequence of chunks to a server, and a server will append them to a file with a provided name. The steps are the following:
- Let’s open the
api/movie.proto
file and add anUploadFile
function to it, as well as our request and response structures:service MovieService { rpc GetMovieDetails(GetMovieDetailsRequest) returns (GetMovieDetailsResponse); ...