/rock-paper-sissor-game

Primary LanguageJavaGNU General Public License v3.0GPL-3.0

Rock Paper Scissors game microservices

The Rock Paper Scissors game project provides infrastructure, REST and gRPC APIs for the Rock Paper Scissors game.

Prerequisites

  • Docker Desktop
  • Java 11 or higher

Technology stack

** H2 in-memory database engine is used for dev and it profiles only

1. Installation of Docker Desktop

  • 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.

2. Deployment of the infrastructure

  • 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.

health-checks ** Status gets refreshed every 10 seconds

3. Building of the necessary common libraries

  • 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

4. Running the RPS game command microservice from the command line

  • 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.

5. Running the RPS game query microservice from the command line

  • 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

6. Running the Score command microservice from the command line

  • 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

7. Running the Score query microservice from the command line

  • 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

Useful links

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:

Microservice patterns used

Useful Docker commands

  • 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

BloomRPC Configuration

  • Launch the BloomRPC application.
  • Add path to proto folder of the rps-grpc-lib project to BloomRPC paths:

add new path

  • Add testing service definition proto file:

add server definition

  • Add gRPC server url and port:

add gRPC server url and port

  • Query the gRPC service:

query gRPC services

Apache Bench for microservice performance testing

  • 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.