Skip to content

Repository files navigation

Microservices

The pinnacle of microservices architecture!


Ebooks

Flow

sequenceDiagram
    autonumber

    participant C as Client
    participant AUTH as Auth Service
    participant CUST as Customer Service
    participant PROD as Product Service
    participant ORD as Order Service
    participant PAY as Payment Service
    participant BUS as Kafka

    %% Authentication
    C->>AUTH: POST /auth
    AUTH-->>C: 200 OK (JWT)

    %% Customer Registration
    C->>CUST: POST /customers
    CUST-->>C: 201 Created (Customer)

    %% Product Registration
    C->>PROD: POST /products
    PROD-->>C: 201 Created (Product)

    %% Order Creation
    C->>ORD: POST /orders
    ORD-->>C: 201 Created (Order)

    ORD->>BUS: Publish OrderCreated
    BUS-->>PAY: Consume OrderCreated
    Note right of PAY: Create payment

    rect rgba(46,204,113,0.15)
        Note over C,ORD: Payment Approval Flow

        C->>PAY: PUT /payments/{id}/approve
        PAY-->>C: 204 No Content

        PAY->>BUS: Publish PaymentApproved
        BUS-->>ORD: Consume PaymentApproved

        Note right of ORD: Complete order
    end

    rect rgba(231,76,60,0.15)
        Note over C,ORD: Payment Cancellation Flow

        C->>PAY: PUT /payments/{id}/cancel
        PAY-->>C: 204 No Content

        PAY->>BUS: Publish PaymentCanceled
        BUS-->>ORD: Consume PaymentCanceled

        Note right of ORD: Cancel order
    end
Loading

Architecture, Design and Principles

Patterns

Technologies and Tools

Docker

docker compose up --detach --build --remove-orphans

Parent and Starter

Install Into Local Maven Repository: mvn clean install

Tools

  • Kong: http://localhost:8002

  • Keycloak: http://localhost:8005 Username: admin Password: password

  • Kafka: http://localhost:9000

  • Mongo: http://localhost:27018

  • Redis: http://localhost:6380

  • Logs: http://localhost:5601/app/management/data/index_management/data_streams

  • APM: http://localhost:5601/app/apm/services

Services

AuthService

Localhost: http://localhost:8010

Docker: http://localhost:9010

Kong: http://localhost:8000/authservice

Method Endpoint Description
GET /auth Get
POST /auth Auth
POST /users Save
DELETE /users/{id} Delete

ConfigurationService

Localhost: http://localhost:8015

Docker: http://localhost:9015

Kong: http://localhost:8000/configurationservice

Method Endpoint Description
GET /configurations List
GET /configurations/{id} Get
POST /configurations Create
DELETE /configurations/{id} Delete
PATCH /configurations/{id}/value/{value} Update Value

CustomerService

Localhost: http://localhost:8020

Docker: http://localhost:9020

Kong: http://localhost:8000/customerservice

Method Endpoint Description
GET /customers List
GET /customers/{id} Get
POST /customers Create
PUT /customers/{id} Update
DELETE /customers/{id} Delete

ProductService

Localhost: http://localhost:8025

Docker: http://localhost:9025

Kong: http://localhost:8000/productservice

Method Endpoint Description
GET /products List
GET /products/{id} Get
POST /products Create
PUT /products/{id} Update
DELETE /products/{id} Delete

OrderService

Localhost: http://localhost:8030

Docker: http://localhost:9030

Kong: http://localhost:8000/orderservice

Method Endpoint Description
GET /orders List
GET /orders/{id} Get
POST /orders Create

PaymentService

Localhost: http://localhost:8035

Docker: http://localhost:9035

Kong: http://localhost:8000/paymentservice

Method Endpoint Description
GET /payments List
GET /payments/{id} Get
GET /payments/order/{orderId} Get By Order Id
PATCH /payments/{id}/approve Approve
PATCH /payments/{id}/cancel Cancel

Examples

Cache

@RequiredArgsConstructor
@Service
public class ProductCacheService {
    private static final String ITEM_CACHE = "product";
    private static final String LIST_CACHE = "product-list";
    private final ProductRepository repository;

    @Cacheable(cacheNames = LIST_CACHE, sync = true)
    public List<Product> get() {
        return repository.findAll();
    }

    @Cacheable(cacheNames = ITEM_CACHE, key = "#id", sync = true)
    public Optional<Product> get(final UUID id) {
        return repository.findById(id);
    }

    @Caching(
        put = @CachePut(cacheNames = ITEM_CACHE, key = "#result.id"),
        evict = @CacheEvict(cacheNames = LIST_CACHE, allEntries = true)
    )
    public Product save(final Product product) {
        return repository.save(product);
    }

    @Caching(evict = {
        @CacheEvict(cacheNames = ITEM_CACHE, key = "#id"),
        @CacheEvict(cacheNames = LIST_CACHE, allEntries = true)
    })
    public void delete(final UUID id) {
        repository.deleteById(id);
    }

    @Caching(evict = {
        @CacheEvict(cacheNames = ITEM_CACHE, allEntries = true),
        @CacheEvict(cacheNames = LIST_CACHE, allEntries = true)
    })
    public void delete() {
        repository.deleteAll();
    }
}

Kafka

echo 'KEY:{"Key":"KEY"}' | docker exec -i kafka /opt/kafka/bin/kafka-console-producer.sh --bootstrap-server localhost:9094 --topic TOPIC --property parse.key=true --property key.separator=:
docker exec -i kafka /opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9094 --topic TOPIC --from-beginning --property print.key=true --property key.separator=:

About

Screaming Architecture, Clean Architecture, Event-Driven Architecture, Clean Code, DDD, SOLID, Test Pyramid, Patterns (Ambassador, Circuit Breaker, Mediator, Outbox, Result, Retry, Strategy), Java 25, Spring Boot 4, Kong, Keycloak, Kafka, MongoDB, Redis, Elastic, Testcontainers, Docker

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages