This project demonstrates on how to set-up gRPC in a Spring Boot application.
This sample project is based on Microservices with gRPC [Java + Spring Boot + Protobuf] udemy course.
There are 3 services in this demo:
- aggregator service: Is a HTTP Rest API using Spring Boot.
- user service: Is a gRPC service using Spring Boot with a
H2 Database
database. - Item service: Is a gRPC service using Spring Boot with a
H2 Database
database.
- Clone this repository
git clone https://github.com/guedim/spring-projects.git
- Move to the directory
grpc-flix
cd spring-projects/grpc-flix
- To build all services docker images (aggregator, user and movies) run next command:
docker-compose build
For create, start and attach all containers, please run next docker-compose command:
docker-compose up
Finally, aggregaror-service
expose two methods
/user/{loginId}
: GET http method for listing user recommended genre movies. This http method call gRPCuser-service
andmovie-service
.user-service
: Find user by loginId and returns user genre.movie-service
: Return all movies with same genre.
For testing purposes, run next commands:
curl --location --request GET 'localhost:8080/user/matico'
/user/
: PUT http method for update user genre movies. This http method call gRPCmovie-service
.
For testing purposes, run next commands:
curl --location --request PUT 'localhost:8080/user/' --header 'Content-Type: application/json' --data-raw '{"loginId": "matico","genre": "DRAMA" }'