Search⌘ K
AI Features

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 TokenizeRequest message that contains a string and a delimiter.

  • It returns a stream of Result messages where each message represents a tokenized part of the original string.

Follow these steps:

  1. Define the RPC in a .proto file: Define the RPC in the service definition in the proto file.

  2. Implement the server code: Implement the server logic to handle the request and return the tokenized response.

  3. 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. ...