- Notifications
You must be signed in to change notification settings - Fork7
ashutoshsahoo/distributed-transactions-kafka
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
There are three microservices:order-service - it sendsOrder events to the Kafka topic and orchestrates the process of a distributed transactionpayment-service - it performs local transaction on the customer account basing on theOrder pricestock-service - it performs local transaction on the store basing on number of products in theOrder
Here's the diagram with our architecture:
(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
- Use docker to deploy kafka with registry.
Set docker host ip
export DOCKER_HOST_IP=127.0.0.1or 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 buildRun application
- order-service
cd order-servicegradle clean bootRunOpenswagger-ui.
- payment-service
cd payment-servicegradle clean bootRun- stock-service
cd stock-servicegradle clean bootRunUse 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'- 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
- 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"}]'
About
Distributed Transactions in Microservices with Kafka Streams and Spring Boot
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
