Exercise: Encode Bi-Directional Streaming API
Explore how to implement a bi-directional streaming API in a gRPC TextEditorService by defining RPCs, coding server logic for encoding text streams, and building a client to send and receive encoded messages. This exercise guides you through testing asynchronous streaming interactions in Java.
Encode text RPC
In this exercise, your goal is to implement an encode bi-directional streaming API in a TextEditorService.
The function takes a stream of
Requestmessages where each message contains a string.It returns a stream of
Resultmessages where each message represents an encoded version of the input string.
Follow these steps:
Define the RPC in a .proto file: Define the RPC in the service definition in the proto file.
Implement the server code: Implement the server logic to handle the bi-directional streaming requests and return the encoded responses.
Test the server code by implementing the client: Ensure the client can send multiple strings and receive the encoded strings back.
Example:
The client will send a stream of strings (“hello”, “world”, “from”, “gRPC!”) and the server will respond with a stream of encoded strings (“ifmmp”, “xpsme”, “gspn”, “hSQD"”).
Good luck!
Step 1: Define the RPC in the .proto file
Add the encode RPC to the TextEditorService in the ... ...