Search⌘ K
AI Features

Exercise: Concatenate Client Streaming RPC

Understand how to implement a client streaming RPC in gRPC by creating a TextEditorService that concatenates multiple streamed text requests into one result. Learn to define the RPC in a proto file, handle streaming on the server side with StreamObserver, and test the functionality with an asynchronous client in Java.

Concatenate text RPC

In this exercise, your goal is to implement a concatenate RPC Client Streaming API in a TextEditorService.

  • The function takes a stream of Request messages where each message contains a string.

  • It returns a single Result message that represents the concatenated string of all inputs.

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 streaming requests and return the concatenated response.

  3. Test the server code by implementing the client: Ensure the client can send multiple strings and the server responds with the concatenated string.

The client will send a stream of strings, “hello”, “world”, “from”, and “gRPC!”, and the server will respond with a single string “hello world from gRPC! ”.

Good luck!


Step 1: Define the RPC in the .proto file

Update the service definition in text-editor.proto to ...