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
🚫 gRPC Anti-Patterns & When Not to Use It
🚀 gRPC Streaming Performance Comparison
🚀 ALL Spring boot gRPc Post