Skip to content

DawidStankiewicz/microservices-java-example

Repository files navigation

Work in progress πŸ”œ

microservices java example

Features demonstrated

βœ… Microservice in Spring Boot with REST API

  • pool-service with PoolRepository created using @RepositoryRestResource

βœ… DB service

  • postgres

βœ… Centralized & boot time loaded service configuration

  • Spring Cloud configuration server with git-based backend
  • pool-service connects to configuration-server on boot time and loads available configuration based on spring.profiles.active property (e.g. java -Dspring.profiles.active=dev -jar target\pool-service-0.0.1-SNAPSHOT.jar)

βœ… Version controlled configuration

  • configuration-server looks for configuration on git (at configuration directory)

βœ… Microservices can refresh when a new configuration appears

  • while using @RefreshScope annotation, Spring Boot Actuator adds /refresh endpoint to refresh the service and reread the configuration form configuration-server
  • applied in pool-service and results-service

πŸ”œ Secrets in microservice's configuration are encrypted (like password to database)

βœ… Auto discovery of microservices

  • pool-service and result-service register themselves in discovery service

βœ… Feign Client with HATEOAS example

  • check PoolVotesFeignClient
  • example of reading collection from _embedded HAT+JSON using CollectionModel

βœ… Microservices resilience patterns

Check current state at /actuator/health.
Patterns are configured in results-service.

  • βœ… Retry
  • βœ… Circuit Breaker
  • βœ… Rate Limiter
  • βœ… Bulkhead
  • βœ… Fallback
  • πŸ”œ Cache

βœ… Deployment using Docker containers

πŸ”œ Automatic service replication

βœ… Automatic health-check endpoint using Spring Actuator

  • pool-service has in its pom.xml spring-boot-starter-actuator dependency, so pool-service status can be retrieved from /actuator/health

βœ… Automatic health checks

  • βœ… Docker Compose health checks
  • βœ… Kubernetes health checks

πŸ”œ Service monitoring

βœ… Gateway service

  • gateway-server as reverse proxy for all services registered in discovery-service

πŸ”œ OAuth2

πŸ”œ JWT token

πŸ”œ Messaging system - Spring Cloud Stream + Kafka

πŸ”œ CI/CD pipelines for each module

πŸ”œ Unit tests job

πŸ”œ Integration tests job

πŸ”œ Coverage job

πŸ”œ Build job + artifactory

πŸ”œ Data caching

πŸ”œ Logging aggregation

Start solution

Docker compose

Run the whole solution on localhost using single script:

bash build_and_start_compose.sh

if you have already built services' jars, then you can skip build part and just start docker compose:

bash start_compose.sh

Kubernetes

If you have installed kubernetes and already have running minikube cluster, then you can start the solution using:

bash build_and_start_kubernetes.sh

It will compile jar file for each service, build docker image available for the minikube cluster and deploy services on the cluster.

Then you can use this script to just start services:

bash start_kubernetes.sh

To stop them use:

bash stop_kubernetes.sh

Gateway server will be exposed on minikube IP (which you can check by typing minikube ip in your terminal), e.g.:

curl 172.21.58.62:8072/actuator/health

Template

If you wish to use this repository as your next project starter, remember to extract each service to its own repository. Here, all services (and configuration) are in single git repository to simplify the example.

About

Example of microservices architecture and best practices using Java and Spring Cloud & Spring Boot

Topics

Resources

Stars

Watchers

Forks

Contributors