The Rock Paper Scissors game project provides infrastructure, REST and gRPC APIs for the Rock Paper Scissors game.
- Rock Paper Scissors game command microservice
- Rock Paper Scissors game query microservice
- Score command microservice
- Score query microservice
- Docker Desktop
- Java 11 or higher
- OpenJDK 11
- Maven 3.6.0
- Spring Boot 2.6.1
- Lombok 1.18.20
- MapStruct
- Apache ZooKeeper 3.5.9
- Apache Kafka 2.8.1
- MongoDB NoSQL 3.0
- MariaDB RDBMS 2.7.4
- H2 Database Engine
- OpenAPI 3.0
- gRPC framework 1.32.1
- Hibernate Validator
- Micrometer 1.8.0
- JUnit 5.8.2
- Mockito 3.9.0
- Spock 2.1
- Apache Groovy 3.0.9
- JaCoCo - unit and integration test coverage
- Flyway - database version control
- Prometheus - metrics database
- Grafana - metrics visualization
- ELK Stack - log aggregation and monitoring in a centralized way
- Redis - cache management
** H2 in-memory database engine is used for dev and it profiles only
- If Docker Desktop is not already installed navigate to the docker website download and install it on your local machine.
- To check if it is installed, you can simply run the command:
> docker -v
- Docker Compose is also required. To check if it is installed, you can simply run the command:
> docker compose version
- If it is not already installed navigate to the Docker Compose website and install it on your local machine.
- Check if Docker Swarm mode is active. To check it, you can simply run the command:
> docker info
- If it is not already active, you can simply run the command:
> docker swarm init
to activate it.
- Navigate to the root directory of the RPS Game project on your computer and run the docker compose command below to deploy necessary infrastructure on docker containers in the background.
> docker compose -f docker-compose-general.yml -f docker-compose-kafka.yml -f docker-compose-metrics.yml -f docker-compose-api.yml up -d
- Verify that all necessary infrastructure and metrics containers are up and running.
> docker compose -f docker-compose-general.yml -f docker-compose-kafka.yml -f docker-compose-metrics.yml -f docker-compose-api ps
- Navigate to the health checker microservice:
> localhost/status/hc-ui
and make sure that all the RPS game microservices are up and running.
** Status gets refreshed every 10 seconds
- Navigate to the common/rps-grpc-lib directory on your computer.
> cd common/rps-grpc-lib
- And run "mvn clean install" in the root directory of the rps-grpc-lib project to generate Java model classes and service descriptions for microservices from proto3 models.
> mvn clean install
- Navigate to the common/cqrs-es-framework directory on your computer.
> cd common/cqrs-es-framework
- And run "mvn clean install" in the root directory of the cqrs-es-framework project to create jar file and install it to local .m2 repository.
> mvn clean install
- Navigate to the common/rps-common-lib directory on your computer.
> cd common/rps-common-lib
- And run "mvn clean install" in the root directory of the rps-common-lib project to create jar file and install it to local .m2 repository.
> mvn clean install
- Navigate to the root directory of the microservice on your computer.
> cd microservices/rps-cmd-service
- Run "mvn clean package -P" in the root directory to create the Rock Paper Scissors Game Command microservice app.
> mvn clean package -Pdev
- Run microservice from the command line using spring boot maven plugin. Run "mvn spring-boot:run -Dspring.profiles.active=" in the root directory of the microservice to launch the Rock Paper Scissors Game Command microservice app.
> mvn spring-boot:run -Dspring.profiles.active=dev
- Or run microservice from the command line. Run "java -jar target/rps-cmd-service.jar" in the root directory of the microservice to launch the Rock Paper Scissors Game Command microservice app.
> java -jar target/rps-cmd-service.jar
- Open any browser and navigate to the microservice Open API 3.0 definition (REST API).
http://localhost:8081/rps-cmd-api/swagger-ui/index.html or
http://host.docker.internal/rps-cmd-api/swagger-ui/index.html
Note: NGINX is used as API gateway so if you deploy the microservices on docker containers you should remove port number from the url.
- Navigate to the root directory of the microservice on your computer.
> cd microservices/rps-qry-service
- Run "mvn clean package -P" in the root directory to create the Rock Paper Scissors Game Query microservice app.
> mvn clean package -Pdev
- Run microservice from the command line using spring boot maven plugin. Run "mvn spring-boot:run -Dspring.profiles.active=" in the root directory of the microservice to launch the Rock Paper Scissors Game Query microservice app.
> mvn spring-boot:run -Dspring.profiles.active=dev
- Or run microservice from the command line. Run "java -jar target/rps-qry-service.jar" in the root directory of the microservice to launch the Rock Paper Scissors Query microservice app.
> java -jar target/rps-qry-service.jar
- Open any browser and navigate to the microservice Open API 3.0 definition (REST API).
http://localhost:8082/rps-qry-api/swagger-ui/index.html or
http://host.docker.internal/rps-qry-api/swagger-ui/index.html
- Navigate to the root directory of the microservice on your computer.
> cd microservices/score-cmd-service
- Run "mvn clean package -P" in the root directory to create the Score Command microservice app.
> mvn clean package -Pdev
- Run microservice from the command line using spring boot maven plugin. Run "mvn spring-boot:run -Dspring.profiles.active=" in the root directory of the microservice to launch the Score Command microservice app.
> mvn spring-boot:run -Dspring.profiles.active=dev
- Or run microservice from the command line. Run "java -jar target/score-cmd-service.jar" in the root directory of the microservice to launch the Score Command microservice app.
> java -jar target/score-cmd-service.jar
- Open any browser and navigate to the microservice Open API 3.0 definition (REST API).
http://localhost:8083/score-cmd-api/swagger-ui/index.html or
http://host.docker.internal/score-cmd-api/swagger-ui/index.html
- Navigate to the root directory of the microservice on your computer.
> cd microservices/score-qry-service
- Run "mvn clean package -P" in the root directory to create the Score Query microservice app.
> mvn clean package -Pdev
- Run microservice from the command line using spring boot maven plugin. Run "mvn spring-boot:run -Dspring.profiles.active=" in the root directory of the microservice to launch the Score Query microservice app.
> mvn spring-boot:run -Dspring.profiles.active=dev
- Or run microservice from the command line. Run "java -jar target/score-qry-service.jar" in the root directory of the microservice to launch the Score Query microservice app.
> java -jar target/score-qry-service.jar
- Open any browser and navigate to the microservice Open API 3.0 definition (REST API).
http://localhost:8084/score-qry-api/swagger-ui/index.html or
http://host.docker.internal/score-qry-api/swagger-ui/index.html
For testing gRPC API (make sure that you are using correct grpc port for a profile), please consider the following options:
For testing REST API, you can also consider the following options:
For testing MongoDB, you can also consider the following options:
To get an idea of HTTP/2 performance, you can follow the link below:
- Domain Driven Design (DDD)
- Command Query Responsibility Segregation (CQRS)
- Event sourcing (ES)
- API Gateway
- Gateway routing
- Gateway offloading
- Database per service
- Polyglot persistence
- Bounded context
- Domain event
- Service instance per container
- Health Check API
- Application metrics
- Messaging
- Idempotent consumer
- Server side discovery
- Log aggregation
- When we don't need infrastructure containers anymore, we can take down containers and delete their corresponding volumes using the down command below:
> docker compose -f docker-compose-general.yml -f docker-compose-kafka.yml -f docker-compose-metrics.yml -f docker-compose-elk.yml down -v
- Launch the BloomRPC application.
- Add path to proto folder of the rps-grpc-lib project to BloomRPC paths:
- Add testing service definition proto file:
- Add gRPC server url and port:
- Query the gRPC service:
- Download Apache Bench tool on your computer.
- Launch CLI and type ab -n 1000 -c 10 http://:/contect path and endpoint/ to benchmark microservice.
> ab -n 1000 -c 10 http://127.0.0.1:8083/score-qry-api/v1/scores
-n 1000 is the number of requests to perform for the benchmarking session. The default is to just perform a single request which usually leads to non-representative benchmarking results. -c 10 is the concurrency and denotes the number of multiple requests to perform at a time. Default is one request at a time.