This project is a follow-up project for the microservices-level1 repository for creating microservices. In this repository, we use the following technologies:
-
Spring Boot
-
Java
-
REST services
-
Lombok
-
MongoDB document database (embedded) with Book data
We have added domain data on books because most applications interact with some form of data storage. Spring Data MongoDB is one option that requires a only few steps, and using the embedded version (via a test dependency), we avoid spinning up a separate instance and creating an additional service…for now.
For the domain, we are using pre-populated data for some of my favorite books that get saved to the embedded database when the application is started. While the data is hard-coded for our embedded test database, it gives us a first step toward interacting with stored data. One of our later goals will be to separate this embedded database to a service itself, populate it with more complete data, and handle typical operations (CRUD), more closely simulating the real business world.
We have 2 services in this repository: service1
and service2
. Our architecture is the same as the previous Level1; however, what is different is the data we are passing. This project passes Book
objects (previous one passed a string message). Responsibilities of each service are outlined below.
-
Service1: backend service for storing data (embedded MongoDB database) and hosting the REST api endpoint (
localhost:8081/db
) -
Service2: client REST service for calling the available REST endpoint in service1 and returning any results (4 books)
With both services running, we can use service2 to execute whatever service(s) created on the backend (service1).
There are a variety of reasons businesses and users might choose to develop applications in a microservices architecture. Some potential reasons are listed below.
-
Scalability
-
Functionality independence (separating grouped features, often for reliability)
-
Maintenance simplicity (changes only affect pieces, and less likely to impact whole)
-
Shift resource load (from large instance running single monolith application, to many smaller instances hosting/coordinating microservices)
To reproduce this intro example, please follow the steps.
-
Clone this repository
-
Run each service (either from an IDE or command line)
-
Test backing service: Open a command line window and execute
curl localhost:8081/db/books
. -
Test client service: Open a command line window and execute
curl localhost:8080/hello
. -
See the results of my favorite books appear :)
-
Blog post: Microservices Level 2
-
Level1 - Sending a string message from one Spring Boot app to another