How rformagio/java-grpc works
Project type and purpose
• This is a distributed Java application demonstrating a gRPC-based microservice interaction using Spring Boot. It consists of two separate services:
a. grpc-client – a RESTful API that accepts HTTP GET requests for postal codes (CEP), invokes a local gRPC stub, and returns address data.
b. grpc-server – a gRPC server that implements the CepService defined in a .proto file, looks up address data in a map, and responds to gRPC calls.
File structure
• Top-level directories:
• grpc-client – Spring Boot REST app + gRPC client stub
• grpc-server – Spring Boot gRPC server
• Each service has:
• Dockerfile & init.sh – containerization scripts
• pom.xml – Maven configuration with Spring Boot, grpc-spring-boot-starter and protobuf‐maven‐plugin
• src/main/proto – CepService.proto shared by both client and server
• src/main/java/br/com/rformagio/grpc – entry points (GrpcClient.java, GrpcServer.java), controllers/services
• src/main/resources/application.yml – service configuration
• The top-level pom.xml orchestrates multi‐module builds.
README for additional insights
• The README explains the role of Protobuf, the .proto file, and gRPC stub/skeleton generation via Maven plugins.
• It outlines the runtime flow: HTTP → stub → gRPC server → in-memory map lookup → response.
a. Components
1. HTTP Client (e.g., Browser or curl)
2. REST API Layer (grpc-client – AddressController)
3. gRPC Stub & Channel (AddressClientService + generated gRPC classes)
4. Network (TCP on port 6565 or configured port)
5. gRPC Server (grpc-server – GrpcServer entrypoint)
6. Business Logic (CepServiceImp)
7. Data Store (in-memory Map)
b. Relationships & Data Flow
– HTTP GET /address/{cep} → AddressController
– Controller calls AddressClientService.getAddressByCep(cep)
– Service uses gRPC stub to open channel → sends AddressRequest(cep)
– Server’s GrpcServer skeleton dispatches to CepServiceImp.getAddress
– CepServiceImp looks up Map[cep] → builds AddressResponse
– Response flows back over gRPC → stub → AddressClientService → controller → HTTP response JSON
c. Architectural Patterns & Principles
– Client-Server RPC pattern (stub/skeleton)
– Separation of concerns: REST front end vs. RPC backend
– Protobuf for interface definition (IDL)
– Containerizable microservices (Dockerfiles present)
d. Key Technologies & Frameworks
– Java 11+
– Spring Boot + net.devh grpc‐spring‐boot‐starter
– gRPC / Protocol Buffers
– Maven for build & code generation
– Docker for containerization
4. Inside grpc-server: show GrpcServer skeleton receiving calls → delegating to CepServiceImp → in-memory Map.
– Application code vs. generated code vs. data store vs. network interface.
7. Maven build step generating stubs/skeletons from .proto.