This project demonstrates client-side streaming using gRPC with a Spring Boot application. It includes:
A gRPC server that receives file chunks via stream and reconstructs them.
A REST client that accepts
multipart/form-data
uploads and streams the file to the server over gRPC.
- Java 11
- Spring Boot 2.7.x
- gRPC (1.54.0)
- Protocol Buffers (proto3)
- Maven
- WebFlux + Server-Sent Events (SSE) for REST integration
β Code Repository LinkΒ
LinkΒ -Β grpc-client-streaming
1. Start gRPC Server
- cd grpc-client-streaming-upload-server mvn spring-boot:run
2. Start REST Client
- cd grpc-client-streaming-upload-client mvn spring-boot:run
3. Upload a File via REST
- curl -X POST http://localhost:8080/upload -H "Content-Type: multipart/form-data" -F "file=@/path/to/your/file.txt"
β Project Structure
Server: grpc-client-streaming-upload
- grpc-client-streaming-upload/ βββ src/ β βββ main/ β βββ java/com/example/grpc/ β β βββ GrpcApplication.java # Spring Boot main class β β βββ FileUploadService.java # gRPC service implementation β βββ proto/upload.proto # gRPC service and message definitions β βββ resources/application.properties # gRPC + HTTP port config βββ pom.xml # Maven config with protobuf plugin
Client: grpc-client-streaming-upload-client
- grpc-client-streaming-upload-client/ βββ src/ β βββ main/ β βββ java/com/example/grpc/ β β βββ GrpcClientApplication.java # Spring Boot main class β β βββ FileUploadController.java # REST endpoint that calls gRPC client β βββ proto/upload.proto # Same proto for stub generation β βββ resources/application.properties # gRPC target address config βββ pom.xml # Maven config with protobuf plugin
π Quick Explanation of Key Classes
𧬠Proto FileΒ
- syntax = "proto3";option java_multiple_files = true;option java_package = "com.example.grpc";option java_outer_classname = "FileUploadProto";service FileUploader {rpc UploadFile (stream FileChunk) returns (UploadStatus);}message FileChunk {string filename = 1;bytes content = 2;}message UploadStatus {bool success = 1;string message = 2;}
π Diagram: REST β gRPC Flowe
[User/Client] ββHTTP/POSTββ> REST Controller (Spring Boot)
ββββΆ Reads multipart file
ββββΆ Opens gRPC stream
ββββΆ Sends file chunks
ββββΆ gRPC Server handles each chunk
ββββΆ On complete, sends UploadStatus
- [User/Client] ββHTTP/POSTββ> REST Controller (Spring Boot) ββββΆ Reads multipart file ββββΆ Opens gRPC stream ββββΆ Sends file chunks ββββΆ gRPC Server handles each chunk ββββΆ On complete, sends UploadStatus