A microservice architecture consisting of 3 microservices that interact with each other in Spring Boot using Gradle in Java 8
Open and view the Project using the .zip
file provided or at my Github Repository
The project has 5 branches: master
, hard-coding
, mongo
, eureka
and docker
master
contains aggregate code of all brancheshard-coding
contains hardcoded data for APIsmongo
contains embedded mongodb connection with the serviceseureka
contains service discovery for the microservicesdocker
contains a dockerized version of the app
This application doesn't have a proper UI and focuses on the Backend and the Database part
You would require the following tools to develop and run the project:
- MongoDB
- Docker
- Java 8
- SpringBoot
- Gradle
- A text editor or an IDE (like IntelliJ)
-
Setup Java 8
- Follow the steps mentioned here
-
Install Gradle in your system. It’s highly recommended to use an installer:
As a last resort, if neither of these tools suit your needs, you can download the binaries from Gradle Org
-
Setup MongoDB
- Follow the steps mentionedhere
- Create 3 different project using Spring Initializr.
- Create resources and model classes for all of them.
- Building movie catalog service API, movie info service API and rating data service API.
- Creating replicas in the movie catalog service for the classes used in the services other two services.
- Have movie catalog service API call the other two services.
- The code will be in the
master
branch.
- The services created in the previous step will be used to create an architecture with embedded DB.The hardcoded data will be removed from the app.
- The code will be in the
mongo
branch. - Two databases have been created, one for each
Movie-Info-Service
andRating-data-Service
. - New Entities were made in
Rating-data-Service
. - PostMapping methods were added for the above mentioned two services.
- Still hardcoded URL's are used from
Movie-Catalog-Service
but will be changed in future.
-
The code will be in the
eureka
branch. -
New spring boot application called
disovery-server
is created whioh acts as the Eureka Server. All services are registered here. -
New Dependencies are added in the other 3 services to act as Eureka Clients and are assigned name in the
application.properties
files. -
Hardcoded URL's are updated with the service names.
- The code will be in the
docker
branch. - Yet to be implemented
For details now how everything has been implemented, refer the source code.
-
Start the mongo database using the following commands:
- Open a terminal and run
mongod
- Open another terminal and run
mongo
- You can run mongo related commands here
Alternatively, open
MongoDB Compass
and start a new connection to the host athttp://localhost:27017/
- Open a terminal and run
There are multiple commands that are useful when working with gradle
- Open terminal in the root directory of each of the service
- To build the project, use the following command:
gradle build
- To run the project, use the following command:
gradle bootRun
Start the service-discovery(eureka) first and then all the microservices
- Java Brains Tutorial