Exercise: Tokenize Server Streaming RPC
Explore how to implement a tokenize server streaming RPC in gRPC. Learn to define the service and messages in a proto file, build the server-side logic to split and stream tokens, and create a client to receive streamed responses. This lesson helps you practice handling streaming responses and working with RPCs in Java.
Tokenize text RPC
In this exercise, your goal is to implement a tokenize RPC Server Streaming API in a TextEditorService.
The function takes a
TokenizeRequestmessage that contains a string and a delimiter.It returns a stream of
Resultmessages where each message represents a tokenized part of the original 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 request and return the tokenized response.
Test the server code by implementing the client: Ensure the client can send a string and delimiter, and the server responds with a stream of tokenized strings. ...