Skip to content

Ivan-Montes/hexagonal-cqrs-proof

Repository files navigation

hexagonal-cqrs-proof

Microservices in a multimodule Maven project with Hexagonal Architecture, CQRS, and Kafka for synchronizing databases

Components

  • Kafka [9092] + [9093]
  • Kafka-UI [8080]
  • REST API ms-artist with OpenApi Swagger and two separate DB for R/RW actions [8081]
  • REST API ms-media with OpenApi Swagger and two separate DB for R/RW actions [8082]
  • Redis DB in every microservice work as caches to store ID references for other REST APIs
graph RL

subgraph ms-artist
  direction LR
  subgraph ms-artist-ms
   A{{ms-artist}}
  end
  subgraph ms-artist-db
  direction LR
   A1[(NoSql Read Db)]
   A2[(Sql Write Db)]
   A3[(Redis Backup Db)]
   end
end

  Kafka(((Kafka)))
  KafkaUI(KafkaUI)

subgraph ms-media
  direction RL
  subgraph ms-media-ms
   B{{ms-media}}
  end
  subgraph ms-media-db
  direction RL
   B1[(NoSql Read Db)]
   B2[(Sql Write Db)]
   B3[(Redis Backup Db)] 
  end
end  
  
  ms-media-db <--> ms-media-ms
  ms-artist-db <--> ms-artist-ms
  ms-artist -->|Publish| Kafka
  Kafka -->|Subscriber| ms-artist
  ms-media -->|Publish| Kafka
  Kafka -->|Subscriber| ms-media
  KafkaUI <--> Kafka
  B1 <-.SYNCHRO.-> B2
  A1 <-.SYNCHRO.-> A2

Table of contents

Installation

  1. First of all clone or download the project.

  2. Inside the main folder, you could find two docker-compose yaml files.

  3. From there use the command line to start the project in dev or production mode

    **Generate .jar**
    mvn clean package
    
    **Developer mode**  
    docker-compose -f docker-compose-dev.yml up -d

    **Production mode**
    docker-compose -f docker-compose-prod.yml up -d

The dev environment is ready for using with your IDE. The microservice attempts to communicate with Kafka using the local host. In production, it uses the archive Dockerfile to build an image of the project, so you wont need the IDE.

  1. You could stop the project and free resources with any of these orders
    **Developer mode**
    docker-compose -f docker-compose-dev.yml down --rmi local -v
      
    **Production mode**
    docker-compose -f docker-compose-prod.yml down --rmi local -v  

Usage

First of all, please visit the REST API documentation. Replace ${port} for the suitable microservice port:

http://localhost:${port}/swagger-ui/index.html

Kafka-UI allow you to check your Kafka server using a practical dashboard, so visit the following url:

http://localhost:8080

Features

✅ Unit testing for business logic classes

✅ Include two docker-compose yaml files for easy change of environment

✅ Hexagonal Architecture following Clean Architecture principle

✅ CQRS pattern with independent databases for Read or RW actions

✅ DB synchronization by Publisher-Subscriber pattern

✅ Redis DB in every microservice work as caches to store ID references for other REST APIs

Maintainers

Just me, Iván 😅

License

GPLv3 license


Java Maven Spring GitHub Eclipse SonarQube Docker Kafka GPLv3 license

About

Microservices in a multimodule Maven project with Hexagonal Architecture, CQRS, and Kafka for synchronizing databases

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Languages