JMHReif / microservices-level8

Microservices project - Spring Cloud Config for MongoDB and Neo4j configuration

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Microservices Project: Level 8

In this installment of the project, we are implementing Spring Cloud Config for all services that connect to a database. Service1 and service3 connect to MongoDB for book and author data, and service4 connects to Neo4j for book review data.

Technologies

This project is part of a series for creating microservices. In this repository, we use the following technologies:

  • Spring Boot

  • Java

  • REST services

  • Lombok

  • Spring Data

  • MongoDB document database

    • loaded with Book/Author domain data

  • Docker and docker compose

  • Neo4j AuraDB free tier

    • load with Book/Author/Review domain data

  • Spring Cloud Config

For the domain, we loaded a publicly-available UCSD Book Graph dataset that provides books and related information.

Architecture

microservices level8

We have 4 services in this repository: service1, service2, service3, and service4. Responsibilities of each service are outlined below, followed by the changes to execution.

  • Service1: backend service hosting the REST api for book data (MongoDB)

  • Service2: client REST service for calling service1 and returning books

  • Service3: backend service hosting the REST api for author data (MongoDB)

  • Service4: backend service hosting the REST api for review data (Neo4j)

Services 1, 2, and 3 have been packaged into Docker containers, and we are using Docker Compose to run and manage the services together. With all services running in Docker containers, there were a few configuration changes needed, but the applications can communicate and pass data as before. Service4 is currently run locally, but will be containerized and added to our Docker Compose setup later.

We also have a few supporting folders explained below.

  • Config-server: application code to set up the config server for service1, service3, and service4 to reference for MongoDB or Neo4j database credentials

  • Data-neo4j: folder that includes steps and script for loading data set on books, authors, and reviews to Neo4j.

  • Docker-mongodb: folder containing steps and data for starting and loading books and authors data to MongoDB Docker container.

  • Microservices-java-config: holds sample YAML files containing MongoDB or Neo4j database credentials.

Note: Notes how to use the config yaml file are in the readme that folder.

Microservices functions

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)

Executing the services

To reproduce the Docker compose portion of this example, please follow the steps.

  1. Clone this repository

  2. Build each service’s (1, 2, and 3) Docker container (note: if not on arm64 silicon chip, will need to update image names in compose file, as well).

  3. Execute Docker compose with docker-compose up -d.

  4. Test backing service (books): Open a command line window and execute curl localhost:8081/db/books.

  5. Test client service: Open a command line window and execute curl localhost:8080/goodreads/books.

  6. Test backing service (authors): Open a command line window and execute curl localhost:8082/db/authors.

  7. See the results of books or authors appear :)

Separately, we can test the config service and related services with additional steps.

  1. Create a free Neo4j AuraDB instance.

  2. Load the data using the steps in the data-neo4j folder.

  3. Start the config-server project from an IDE or command line.

  4. Test the config server: Open a command line window and execute curl localhost:8888/neo4j-client/default or curl localhost:8888/mongo-client/default.

  5. Start the service1 application from an IDE or command line.

  6. Test backing service (books): Open a command line window and execute curl localhost:8081/db/books.

  7. Start the service3 application from an IDE or command line.

  8. Test backing service (authors): Open a command line window and execute curl localhost:8082/db/authors.

  9. Start the service4 application from an IDE or command line.

  10. Test review backing service: Open a command line window and execute curl localhost:8083/neo/reviews or curl localhost:8083/neo/reviews/178186.

  11. See the results of reviews appear :)

    == Content

Previous steps

  • Level1 - Sending a string message from one Spring Boot app to another

  • Level2 - Retrieving prepopulated Book data from one Spring Boot app to another

  • Level3 - Storing Book data in MongoDB and retrieving all stored books

  • Level4 - Adding new service for author data

  • Level5 - Adding Docker compose to manage services as containers

  • Level6 - Adding new service for review data (in Neo4j)

  • Level7 - Adding Spring Cloud Config for Neo4j database credentials

About

Microservices project - Spring Cloud Config for MongoDB and Neo4j configuration


Languages

Language:Java 69.6%Language:Cypher 16.3%Language:Dockerfile 10.2%Language:Shell 3.8%