Code Monkey home page Code Monkey logo

event-driven-microservices-advanced's Introduction

EVENT DRIVEN MICROSERVICES ADVANCED

CLEAN ARCHITECTURE FOR ORDER-SERVICE

orderService

DOMAIN DRIVEN DESIGN (DDD) FOR ORDER-SERVICE

orderServiceDDD

ORDER STATE TRANSITIONS

Order state transitions

OUTBOX PATTERN

outbox pattern

OUTBOX HAPPY FLOW

outbox happy flow

OUTBOX PAYMENT FAILURE

outbox payment failure

OUTBOX APPROVAL FAILURE

outbox approval failure

CQRS

CQRS

Yes, there is not strong consistency between local database operations and data publishing operation for the customer service, outbox pattern implementation can fix that.

CHANGE DATA CAPTURE (CDC)

  • Use Push method as opposed to Pulling

  • Push database records into target source (Kafka) by reading from Transaction Logs (WAL in Postgres)

    CDC

    Will be replacing the scheduler written in Java:

    CDC VS SCHEDULER

API USAGE

  1. POST request to http://localhost:8184/customers with JSON body:
{
    "customerId":"d215b5f8-0249-4dc5-89a3-51fd148cfb41",
    "username": "user_1",
    "firstName": "Armando",
    "lastName": "Maradona"
}
  1. POST request to http://localhost:8181/orders request to with JSON body:
{
  "customerId": "d215b5f8-0249-4dc5-89a3-51fd148cfb41",
  "restaurantId": "d215b5f8-0249-4dc5-89a3-51fd148cfb45",
  "address": {
    "street": "street_1",
    "postalCode": "1000AB",
    "city": "Amsterdam"
  },
  "price": 200.00,
  "items": [
    {
      "productId": "d215b5f8-0249-4dc5-89a3-51fd148cfb48",
      "quantity": 1,
      "price": 50.00,
      "subTotal": 50.00
    },
    {
      "productId": "d215b5f8-0249-4dc5-89a3-51fd148cfb48",
      "quantity": 3,
      "price": 50.00,
      "subTotal": 150.00
    }
  ]
}
  1. Get the orderTrackingId from the response and query the result with a GET operation to http://localhost:8181/orders/toChangewithOrderTrackingId

You will see that first is PAID (payment-service replied), and roughly after 10 seconds, it is APPROVED (restaurant-service confirmed) if you continue to perform GET operation. Notice that if you perform the previous POST operation multiple times, it will fail, because there are not enough funds, and this can be an example of bad path.

HOW TO LAUNCH THE SERVICES

  1. Run Docker and Kubernetes

  2. Install helm.

  3. Type in terminal:

    helm repo add my-repo https://charts.bitnami.com/bitnami
    helm install my-release my-repo/kafka
    helm install schema my-repo/schema-registry
  4. From the project's root type in terminal: mvn clean install

  5. Go from terminal in the folder Event-Driven-Microservices-Advanced/infrastructure/k8s and type: kubectl apply -f kafka-client.yml

  6. Once the pod is running type in terminal: kubectl exec -it kafka-client -- /bin/bash

  7. Once in the container, let's create the topics needed for running the applications:

    kafka-topics --bootstrap-server my-release-kafka:9092 --create --if-not-exists --topic payment-request --replication-factor 1 --partitions 3
    kafka-topics --bootstrap-server my-release-kafka:9092 --create --if-not-exists --topic payment-response --replication-factor 1 --partitions 3
    kafka-topics --bootstrap-server my-release-kafka:9092 --create --if-not-exists --topic restaurant-approval-request --replication-factor 1 --partitions 3
    kafka-topics --bootstrap-server my-release-kafka:9092 --create --if-not-exists --topic restaurant-approval-response --replication-factor 1 --partitions 3
    kafka-topics --bootstrap-server my-release-kafka:9092 --create --if-not-exists --topic customer --replication-factor 1 --partitions 3
  8. While still inside the container let's verify that all 5 topics have been created with: kafka-topics --zookeeper my-release-zookeeper:2181 --list

  9. Exit from the container and from the folder Event-Driven-Microservices-Advanced/infrastructure/k8s , type: kubectl apply -f postgres-deployment.yml

  10. Wait that postgres is running and after type: kubectl apply -f application-deployment-local.yml

event-driven-microservices-advanced's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.