Simple training project to learn microservices.
This repository is for the core User and Challenge services.
https://github.com/Book-Microservices-v2
A user solves multiplication challenges with factors between 11 and 99. For example, 30x60.
Results and leaderboard are displayed.
- Java 14
- React.js
- Spring Boot 2
- Spring Cloud (Gateway, Consul, Load Balancer, Sleuth)
- Lombok
- Logback
- MongoDB
- JUnit 5
- Mockito
- AssertJ
- RabbitMQ
- Consul (service registry, health checks, load balancing, centralized configuration/logging)
- Docker
- Docker Compose
- Install JDK 14.
- Install MongoDB - see here.
- Create MongoDB cluster which supports sessions (transactions) - see here.
- Install RabbitMQ server - see here.
- Enable RabbitMQ GUI manager using this command:
$ rabbitmq-plugins enable rabbitmq_management
Will be available viahttp://localhsot:15672
If needed, RabbitMQ server can be run manually from within the RabbitMQsbincommand prompt (run as administrator):$ rabbitmq-server start - Install Consul by HashiCorp as a Service Registry - see here.
- To run Consul in dev mode, use the following command:
$ consul agent -node=learnmicro -dev
If port is occupied on Windows, use the following commands:
$ netstat -ano | findstr :\PORT\
$ taskkill /PID \PID\ /F - Consul GUI is available via
http://localhost:8500
NOTE! While adding YAML properties to the Consul KV using the Consul GUI, use 4 spaces instead of tab for indentation.
NOTE! While adding {application},{profile} property using the Consul GUI, need to literally name folder using separator (comma ',' by default; to change separator, specifyspring.cloud.consul.config.profile-separatorwithin bootstrap.properties).
Example: config/defaults,production/application.yml; config/multiplicator,rabbitmq-production/application.yml
To run application specifying active profiles, use the following command:$ ./mvnw spring-boot:run '-Dspring-boot.run.arguments="--spring.profiles.active=rabbitmq-production,production"' - To run the new microservice's instance use the following command from within the microservice's directory:
$ ./mvnw spring-boot:run -Dspring-boot.run.arguments="--server.port=\PORT\" - To run front-end, install
Node.jsandnpm- see here. - To run front-end in the dev mode, use the following command from within the front-end application's directory:
$ npm start
- Install Docker - see here.
- Prepare JAR from within the root folder of the multiplicator service:
NOTE! This command can be used for all the services mentioned below:
$ ./mvnw clean package
NOTE! All the services mentioned below may require running Consul agent to build Docker image properly (see previous section):
$ consul agent -node=learnmicro -dev - Build Docker image for the multiplicator service from within its root folder:
$ docker build -t multiplicator:\VERSION\
NOTE! Version should be provided as #.#.# (e.g. 1.0.0).
If changed, need to update also in Docker Compose file - see here.
NOTE! If project's version tag is changed in POM.xml, need also to edit Dockerfile's COPY command. - Prepare JAR from within the root folder of the gamification service.
- Build Docker image for the gamification service from within its root folder:
$ docker build -t gamification:\VERSION\ . - Prepare JAR from within the root folder of the gateway service.
- Build Docker image for the gateway service from within its root folder:
$ docker build -t gateway:\VERSION\ . - Prepare JAR from within the root folder of the logging service.
- Build Docker image for the logging service from within its root folder:
$ docker build -t logs:\VERSION\ . - Build Docker image for the frontend service from within its root folder:
$ docker build -t challenges-frontend:\VERSION\ . - Build Docker image for the Consul importer service (serves only to import initial configurations by the Consul, exits immediately after completing this task):
$ docker build -t consul-importer:\VERSION\ . - Run the complete system using Docker Compose from within the dockerization folder:
$ docker-compose up - To stop the whole application and completely remove the containers, use the following command from a different terminal:
$ docker-compose down -v - To start additional service's instances, use the following command:
$ docker-compose up --scale \IMAGE_NAME\=\INSTANCES_AMOUNT\