maciejgz / blog

POC of Spring Cloud based microservices application with DDD and hexagonal architecture
1 stars 0 forks source link
clean-architecture clean-code ddd docker hexagonal-architecture java kubernetes microservices spring-boot spring-cloud

Description

POC app of the Spring Cloud microservices architecture written built with DDD and hexagonal architecture.

Services

Spring Cloud and other cloud components

Configuration

Requirements

Custom modules port mapping

Module Ports
Spring Cloud Config server 8888
Eureka server 8761
Gateway service 8080
Simulation service 8099
User services 8100 - 8199
Post services 8200 - 8299
Comment services 8300 - 8399

External modules (docker)

Module Ports
Sonar 9100
Zipkin server 9411
Kafka 29092
Prometheus 9090
Grafana 9091

Profiles

Run sonar analysis

mvn verify sonar:sonar -Dsonar.host.url=http://localhost:9000

verify step is needed to get sonar-project.properties file by maven plugin

Zipkin

Zipkin gathers traces of communication between services.
For K8S environment Zipkin uses HTTP communication: http://localhost:9411.
For dev and mock profiles, apps and Zipkin uses Kafka topic zipkin to gather traces. Kafka has to be started in docker compose.

Kafka

Offset Explorer can be connected to the Kafka cluster run in docker compose with the following way:
offset_explorer_config_1.png
offset_explorer_config_2.png

Monitoring

Monitoring consists of:

Build and run

Build mvn project

mvn clean package

build docker images

Run script

.\build_images.sh

or use spring boot plugin for maven (the latest image version is set by default):

clean package spring-boot:build-image -DskipTests

WARNING: images built with spring boot have problems in kubernetes - memory issue

Development environment - container-free

Warning: to use spring-cloud-config server without git config source, it should be run with native profile

docker-compose -up 

Docker compose environment

\docker\blog.yml

Docker compose environment components:

Kubernetes environment

Go to /k8s/blog/ where build scripts are defined and run commands:

kubectl apply -f zipkin-service.yaml
kubectl apply -f user-service.yaml
kubectl apply -f post-service.yaml
kubectl apply -f gateway-service.yaml
kubectl apply -f comment-service.yaml
kubectl apply -f simulation-service.yaml

Standard K8S service registry and config (ConfigMap and Secrets) are used.

Business requirements - User stories

User

Post

Comment actions

Code organization

DDD

DDD shall be used here based on that: https://wkrzywiec.medium.com/ports-adapters-architecture-on-example-19cab9e93be7 and book. Use ports and adapters (application, core without frameworks, infrastructure as connectors and ports implementation)

Ports and adapters packages

TODO