Skip to content

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

License

Notifications You must be signed in to change notification settings

rafaelfgx/Microservices

Repository files navigation

Microservices

Build

System Design

Tools

Flow

sequenceDiagram
    participant Client
    participant AuthService
    participant CustomerService
    participant ProductService
    participant OrderService
    participant PaymentService
    participant Kafka

    Client->>AuthService: POST /auth
    AuthService-->>Client: JWT

    Client->>CustomerService: POST /customers
    CustomerService-->>Client: Customer Created

    Client->>ProductService: POST /products
    ProductService-->>Client: Product Created

    Client->>OrderService: POST /orders
    OrderService-->>Client: Order Created
    OrderService->>Kafka: OrderEvent Published

    Kafka-->>PaymentService: OrderEvent Consumed
    Note right of PaymentService: Payment Created

    Client->>PaymentService: PUT /payments/order/{orderId}/status/{status}
    PaymentService-->>Client: Payment Status Updated
    PaymentService->>Kafka: PaymentEvent Published

    Kafka-->>OrderService: PaymentEvent Consumed
    Note right of OrderService: Status Updated
Loading

Architecture, Design and Principles

Patterns

Technologies and Tools

Docker

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

Starter

Install Into Local Maven Repository: mvn clean install

Tools

  • Kong: http://localhost:8002

  • Keycloak: http://localhost:8005

    • Username: admin

    • Password: password

    • Role: Manage Realms > microservices > Clients > authservice > Service Accounts Roles > Assign Role > manage-users

  • 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 Get
GET /features List
POST /features Create
GET /features/{feature} Get
DELETE /features/{feature} Delete
PUT /features/{feature}/disable Disable
PUT /features/{feature}/enable Enable
GET /features/{feature}/enabled Enabled
GET /features/groups/{group} Get
GET /properties List
POST /properties Create
GET /properties/{property} Get
DELETE /properties/{property} Delete
PUT /properties/{property}/value/{value} Update Value

CustomerService

Localhost: http://localhost:8020

Docker: http://localhost:9020

Kong: http://localhost:8000/customerservice

Method Endpoint Description
GET /customers List
POST /customers Create
GET /customers/{id} Get
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
POST /products Create
GET /products/{id} Get
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
POST /orders Create
GET /orders/{id} Get

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
PUT /payments/order/{orderId}/status/{status} Update Status

Examples

Cache

@Service
public class ProductService {
    @Cacheable(value = "products")
    public List<Product> get() {
        return repository.findAll();
    }

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

    @CachePut(value = "products", key = "#product.id")
    public Product save(final Product product) {
        return repository.save(product);
    }

    @CacheEvict(value = "products", key = "#id")
    public void delete(final UUID id) {
        repository.deleteById(id);
    }

    @CacheEvict(value = "products", allEntries = true)
    public void delete() {
        repository.deleteAll();
    }
}

ShedLock

<dependency>
    <groupId>net.javacrumbs.shedlock</groupId>
    <artifactId>shedlock-spring</artifactId>
    <version>X.X.X</version>
</dependency>
<dependency>
    <groupId>net.javacrumbs.shedlock</groupId>
    <artifactId>shedlock-provider-mongo</artifactId>
    <version>X.X.X</version>
</dependency>
@Configuration
@EnableSchedulerLock(defaultLockAtMostFor = "5m")
public class ShedLockConfiguration {
    private final MongoClient mongoClient;

    public ShedLockConfiguration(final MongoClient mongoClient) {
        this.mongoClient = mongoClient;
    }

    @Bean
    public MongoLockProvider lockProvider() {
        return new MongoLockProvider(mongoClient, "database");
    }
}
@Component
public class Scheduler {
    @Scheduled(fixedDelay = 5000)
    @SchedulerLock(name = "SchedulerJob", lockAtMostFor = "1m")
    public void job() {
        System.out.println("Executing!");
    }
}

About

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

Topics

Resources

License

Stars

Watchers

Forks

Languages