Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Distributed Transactions in Microservices with Kafka Streams and Spring Boot

NotificationsYou must be signed in to change notification settings

ashutoshsahoo/distributed-transactions-kafka

Repository files navigation

Description

There are three microservices:
order-service - it sendsOrder events to the Kafka topic and orchestrates the process of a distributed transaction
payment-service - it performs local transaction on the customer account basing on theOrder price
stock-service - it performs local transaction on the store basing on number of products in theOrder

Here's the diagram with our architecture:

image

(1)order-service send a newOrder ->status == NEW
(2)payment-service andstock-service receiveOrder and handle it by performing a local transaction on the data
(3)payment-service andstock-service send a reponseOrder ->status == ACCEPT orstatus == REJECT
(4)order-service process incoming stream of orders frompayment-service andstock-service, join them byOrder id and sends Order with a new status ->status == CONFIRMATION orstatus == ROLLBACK orstatus == REJECTED
(5)payment-service andstock-service receiveOrder with a final status and "commit" or "rollback" a local transaction make before

Run application

  • Use docker to deploy kafka with registry.

Set docker host ip

export DOCKER_HOST_IP=127.0.0.1

or on windows powershell

$env:DOCKER_HOST_IP="127.0.0.1"
docker compose -f zk-single-kafka-multiple-schema-registry-ui.yml up -d

Open UI for Apache Kafka atKafka Control Center.

  • Run gradle build to generate avro source files
cd common-libgradle clean build
  • Run application

    • order-service
    cd order-servicegradle clean bootRun

    Openswagger-ui.

    • payment-service
    cd payment-servicegradle clean bootRun
    • stock-service
    cd stock-servicegradle clean bootRun
  • Use following request to generate orders

curl --location --request POST'http://localhost:8080/orders/generate'
  • Use following request to check orders status
curl --location --request GET'http://localhost:8080/orders'

Stop application

  • Use ctrl+c to cancel running applications
  • Use following command to stop and remove kafka containers
docker compose -f zk-single-kafka-multiple-schema-registry-ui.yml down

Kubernetes Deployment

  • Start kafka
helm repo add confluentinc https://confluentinc.github.io/cp-helm-charts/helm repo updatehelm install my-kafka -f ./k8s/kafka/values.yaml confluentinc/cp-helm-charts
  • Application Deployment
gradle clean dockerTagkubectl apply -f ./k8s/zipkinkubectl apply -f ./k8s/app
  • Use following request to generate orders
curl --location --request POST'http://localhost:30001/orders/generate'
  • Use following request to check orders status
curl --location --request GET'http://localhost:30001/orders'
  • Clean up
kubectl delete -f ./k8s/appkubectl delete -f ./k8s/zipkinhelm delete my-kafka
  • Expose Confluent Control Center via NodePort
kubectl patch svc my-kafka-cp-control-center --type='json' -p'[{"op":"replace","path":"/spec/type","value":"NodePort"}]'

Reference


[8]ページ先頭

©2009-2025 Movatter.jp