Skip to content

A microservice architecture deployed in Docker containers, demonstrating distributed systems principles and containerization using Spring Boot, RabbitMQ, Docker Compose, and Elastic Stack monitoring.

Notifications You must be signed in to change notification settings

ElinaZoldnere/Dockerized-Microservices-Demo

Repository files navigation

Dockerized Microservices Demo

This repository contains a microservice architecture deployed in Docker containers. It demonstrates distributed systems principles and containerization using Spring Boot, RabbitMQ, Docker Compose, and Elastic Stack for monitoring.

Overview

The core of the system is the insurance calculator application web service, which calculates insurance premiums based on user requests. The project extends the core application into a microservice architecture by introducing two additional services:

  • Blacklist Service: A synchronously integrated service to verify whether a person is not on a blacklist.
  • Proposal Generator: An asynchronously integrated service (via RabbitMQ) for generating insurance proposals in PDF format. The system uses RabbitMQ for message brokering and MySQL as the database. For monitoring and observability, the Elastic Stack is utilized, including Filebeat, Metricbeat, Logstash, Elasticsearch, and Kibana for data visualization.

All services and supporting components are containerized and orchestrated using Docker Compose. Once the necessary custom images are created, the entire system can be started with a single command.

Key Features

  • Microservices architecture: 10 Docker containers, each representing a distinct service, for modular development and deployment.
  • Spring Boot applications: JDK 21, Spring Boot 3.3, builds, dependencies, and Docker integration managed with Gradle.
  • Configuration management: externalized environment variables and configurations, and Spring Profiles for different environments.
  • Message brokering: RabbitMQ for asynchronous communication, featuring Dead-Letter Queues and Exchanges to handle message failures.
  • Database management: automated database initialization using mysql-init, and schema migrations with Liquibase.
  • Container orchestration: services coordinated using Docker Compose.
  • Monitoring and observability: Elastic Stack (Filebeat, Metricbeat, Logstash, Elasticsearch, and Kibana) for monitoring and visualization.
  • Data persistence: mounted volumes for export data persistence.
  • Local access support: provided local access through port mappings.
  • Static code analysis: Checkstyle for code quality analysis.

More information about the core application, its features, and initial design can be found here: Insurance Application Part 1.

Model with C4 Container Diagram

container_view

How to Run the Project

Although it would be possible to build images and run containers only with docker-compose.yaml, with the necessary configurations, a separate image-building step using Gradle was preferred. This approach provides better control over the workflow, possible debugging, and ensures that dependencies like a freshly built JAR are properly handled before bringing up the containers.

Prerequisites

  • Java Development Kit (JDK) 21 – it can be downloaded either within IDE (like IntelliJ IDEA, Eclipse) or manually - Download JDK 21 Here
    Ensure that the project SDK is set to JDK 21 in your IDE settings (e.g., Project Structure in IntelliJ IDEA).

  • Gradle - only if you are running the project outside an IDE that handles Gradle automatically – Download Gradle Here

  • Docker Desktop - to run the Docker containers locally - Download Docker Desktop Here
    This may require updating Windows:

    • Navigate to: Settings -> Update & Security -> Windows Update -> Advanced Options. Enable the option: Receive updates for other Microsoft products when you update Windows.

    • Return to:Settings -> Update & Security -> Windows Update. Click Check for updates.

    • Ensure WSL2 (Windows Subsystem for Linux) is updated for Docker Desktop to function correctly.

    • In Docker Desktop, after installation: Open Settings. Under the General tab, enable the option: Expose daemon on tcp://localhost:2375 without TLS. For local development it is generally safe.

  • Postman (Desktop App) - to perform POST/GET requests to the REST API endpoints - Download Postman Here

Steps to Run

  1. Clone the repository and navigate to the project directory:
git clone https://github.com/ElinaZoldnere/Dockerized-Microservices-Demo.git
cd Dockerized_Microservices_Demo 
  1. Open the project in your IDE (e.g., IntelliJ IDEA or Eclipse).
  2. Locate the .env.example file in the project root directory. Rename it to .env. Review the .env file and update values if necessary to match your setup, but sample values should also work.
mv .env.example .env
  1. Build the project custom images using Gradle:
./gradlew :black-list-app:docker
./gradlew :doc-generator-app:docker
./gradlew :insurance-calculator-app:docker
./gradlew :elk:filebeat:docker
./gradlew :elk:metricbeat:docker
./gradlew :elk:logstash:docker
  1. Start the Docker containers using Docker Compose:
docker-compose up

You can also run the containers in detached mode with the -d flag:

docker-compose up -d

To stop and remove containers later use:

docker-compose down
  1. Access the application:

REST API endpoints you can test via Postman Desktop App.
As endpoints are secured with Basic Authentication, you have to select Basic Auth and provide the username and password in the request. Username: admin and password: javaguru3 will work for all REST endpoints.
Postman_Basic_Auth

Example JSON (request body content) for testing REST API/POST v1 at http://localhost:8080/insurance/travel/api/v1/

{
  "personFirstName": "Jānis",
  "personLastName": "Bērziņš",
  "personalCode": "123456-12345",
  "personBirthDate": "1990-01-01",
  "agreementDateFrom": "2025-03-10",
  "agreementDateTo": "2025-03-11",
  "selectedRisks": [
    "TRAVEL_MEDICAL",
    "TRAVEL_LOSS_BAGGAGE"
  ],
  "country": "SPAIN",
  "medicalRiskLimitLevel": "LEVEL_15000"
}

Example JSON (request body content) for testing REST API/POST at http://localhost:8080/insurance/travel/api/v2/

{
  "agreementDateFrom": "2025-03-10",
  "agreementDateTo": "2025-03-11",
  "selectedRisks": ["TRAVEL_MEDICAL"],
  "country": "SPAIN",
  "persons": [
    {
      "personFirstName": "Jānis",
      "personLastName": "Bērziņš",
      "personalCode": "123456-12345",
      "personBirthDate": "1990-01-01",
      "medicalRiskLimitLevel": "LEVEL_15000"
    },
    {
      "personFirstName": "Kārlis",
      "personLastName": "Krūmiņš",
      "personalCode": "234567-23456",
      "personBirthDate": "1989-01-01",
      "medicalRiskLimitLevel": "LEVEL_15000"
    }
  ]
}

Please, take into account, the application supports limited number of countries, risk types and limit levels.
Some of the values you can use for testing:
Countries: "LATVIA", "SPAIN", "JAPAN".
Risk types: "TRAVEL_MEDICAL", "TRAVEL_CANCELLATION".
Medical risk limit levels: "LEVEL_5000", "LEVEL_10000", "LEVEL_15000".

Optionally after performing at least one successful request, you can check the results in the database. Picking a valid agreement UUID from the table agreements, you can test the REST API/GET endpoint providing the UUID in the URL.

The web interface can be tested filling in the form fields and submitting the request. No authentication required.

About

A microservice architecture deployed in Docker containers, demonstrating distributed systems principles and containerization using Spring Boot, RabbitMQ, Docker Compose, and Elastic Stack monitoring.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published