Saga pattern with Java => order -> payment -> stock microservices are ready to use

Overview

Order_Payment_Stock_Saga_Pattern

Saga pattern with Java => order -> payment -> stock microservices are ready to use

Docker-compose.yaml

You can see that rabbitmq is necessary for message broker.

Orchestration-based saga is used for implementation.

How to run

git clone [email protected]:grkn/Order_Payment_Stock_Saga_Pattern.git Open IDE from your computer Import Project Run Application.java for each services (I didn't write startup script)

There is only one endpoint for creating order.

POST http://localhost:8089/saga/v1/order
body : [
    {
        "name" : "order1",
        "quantity": 2
    },
    {
        "name" : "order2",
        "quantity": 2
    },
    {
        "name" : "order3",
        "quantity": 1
    }
]
GET http://localhost:8089/saga/v1/order/transaction/{transactionId}
Response : 
    
    {
        "transactionId": "d7c4d073-061d-4f04-8ff6-d1d0de4e1976",
        "name": "order1",
        "quantity": 4,
        "status": "ORDER_FAILED",
        "paymentId": "7260a2ac-233f-441a-aa74-51a9e331afbb"
    }

GET http://localhost:8088/saga/v1/payment/{paymentId}
Response :
    {
        "status": "PAYMENT_COMPLETED",
        "totalPrice": 531.0,
        "transactionId": "506cc494-3594-46a4-8f52-780f7668513d"
    }

Of course there are some failure cases

Buy operation is dump and sometime gives error.

Also stock is limited maybe you can not buy necessary amount.

There are static order names : order1, order2, order3, order4, order5. Other names will give an error

Database are h2 database and each database has one table. You can easily check status from database.

Additional Information :

User sends order request to ORDER service.

ORDER service sends 2 amqp message to PAYMENT service and STOCK service

STOCK service sends related amqp message to ORDER service and PAYMENT service

PAYMENT service sends success or fail to ORDER service.

Statuses that are related with Order, Payment, Stock

ORDER_RECEIVED, ORDER_COMPLETED, ORDER_PENDING, ORDER_FAILED, ORDER_STOCK_COMPLETED

PAYMENT_REQUESTED, PAYMENT_PENDING, PAYMENT_COMPLETED, PAYMENT_FAILED, PAYMENT_AVAILABLE

STOCK_REQUESTED, STOCK_COMPLETED, STOCK_FAILED, STOCK_PENDING

Each service listens the related queue.

Exchange -> sagaExchange

Order service -> orderQueue -> orderDto is payload Payment service -> paymentQueue -> paymentDto is payload Stock service -> stockQueue -> stockDto is payload

image

You might also like...

A distributed lock that supports the use of Redis and Zookeeper, out of the box, fast and easy to use

lock-spring-boot-starter A distributed lock that supports the use of Redis and Zookeeper, out of the box, fast and easy to use 一款基于 Redis 和 Zookeeper

Oct 15, 2022

Tzatziki - Decathlon library to ease and promote Test Driven Development of Java microservices!

Tzatziki Steps Library This project is a collection of ready-to-use Cucumber steps making it easy to TDD Java microservices by focusing on an outside-

Dec 15, 2022

A base repo for creating RPC microservices in Java with gRPC, jOOQ, and Maven.

Wenower Core OSX local installation Install Protocol Buffer $ brew install protobuf Install Postgresql and joopc database and user $ brew install pos

Jan 9, 2022

Java libraries for writing composable microservices

Apollo Status: Archived ⚠️ Apollo is heavily used within Spotify, however, most of its development has recently been done internally leveraging Apollo

Dec 6, 2022

How To Implement Fault Tolerance In Microservices Using Resilience4j

springboot-resilience4j-demo How To Implement Fault Tolerance In Microservices Using Resilience4j? Things todo list: Clone this repository: git clone

Mar 30, 2022

Spring Boot microservices app with Spring Cloud, Robust and resilient backend managing e-Commerce app

Spring Boot microservices app with Spring Cloud, Robust and resilient backend managing e-Commerce app

e-Commerce-boot μServices Important Note: This project's new milestone is to move The whole system to work on Kubernetes, so stay tuned. Introduction

Dec 23, 2022

Hexagon is a microservices toolkit written in Kotlin

Hexagon is a microservices' toolkit (not a framework) written in Kotlin. Its purpose is to ease the building of server applications (Web applications, APIs or queue consumers) that run inside a cloud platform.

Jan 5, 2023

A boilerplate project designed to work as a template for new microservices and help you get in touch with various useful concepts.

Microservice Reference Project This project is inspired by the idea to quickly create a production ready project with all the required infrastructure

Dec 17, 2022

A fast, lightweight and more productive microservices framework

A fast, lightweight and cloud-native microservices framework. Stack Overflow | Google Group | Gitter Chat | Subreddit | Youtube Channel | Documentatio

Jan 5, 2023
Comments
  • ask about Saga

    ask about Saga

    Hi, i am reading your project and I love it. But i have a question, what queue do you use for the message queue, how do you manage the state of each service and how do you tackle and implement "Transaction outbox ". Thank u so much

    opened by fizz12344321 2
Owner
Gurkan İlleez
Gurkan İlleez
Kryptokrona Java SDK for building decentralized private communication and payment systems.

Kryptokrona Java SDK Kryptokrona is a decentralized blockchain from the Nordic based on CryptoNote, which forms the basis for Monero, among others. Cr

null 22 Oct 31, 2022
Hexagonal Architecture Demo Project about Ticketing and Payment

This project is a sample production-ready implementation for demonstrating the power of Hexagonal Architecture (aka Ports And Adapters Pattern) written in Java.

Alican Akkuş 382 Jan 1, 2023
A simple live streaming mobile app with cool functionalities and time extension, and live chat. With a payment system integrated. Server is designed with socket.io to give you full flexibility.

Video Live Streaming Platform Android A simple live streaming mobile app with cool functionalities and time extension, and live chat. With a payment s

Dev-Geek 2 Dec 16, 2022
Integrates with XRPLedger to send token payment to trustline addresses

strategyengine token distribution rest service This service also runs here -- https://fsedistributionservice-56gpv2b23a-uc.a.run.app/ #How to run loca

strategyengine 8 Dec 14, 2022
Tencent Kona JDK17 is a no-cost, production-ready distribution of the Open Java Development Kit (OpenJDK), Long-Term Support(LTS) with quarterly updates.

Tencent Kona JDK17 Tencent Kona JDK17 is a no-cost, production-ready distribution of the Open Java Development Kit (OpenJDK), Long-Term Support(LTS) w

Tencent 59 Nov 30, 2022
Spring Boot DTO Example Tutorial | Data Transfer Object Pattern

springboot-dto-tutorial Spring Boot DTO Example Tutorial | Data Transfer Object Pattern at https://youtu.be/THv-TI1ZNMk Spring Boot DTO Tutorial - Ent

Ramesh Fadatare 20 Nov 16, 2022
Human Resource Management Application on JavaFX using MVC Design Pattern

Human-Resource-Management-System-with-JFoenix Human Resource Management Application on JavaFX using MVC Design Pattern Built With Java JavaFX - FXML C

Bahadır Ünal 0 Mar 18, 2022
Demo Repo for our CDC-based Strangler Fig Pattern Session @ VoxxedDays Romania 2021

Strangler Fig Pattern Demo Build applications Before being able to spin up the docker-compose based demo environment please make sure to successfully

Hans-Peter Grahsl 5 Feb 20, 2022
A React Native project starter with Typescript, a theme provider with hook to easy styling component, a folder architecture ready and some configs to keep a codebase clean.

React Native Boilerplate Folder structure : src ├── assets │   ├── audios │   ├── fonts │   ├── icons │   └── images ├── components │   ├── Layout.tsx

LazyRabbit 23 Sep 1, 2022
An AI companion who is eager to learn and would love to see the world through your eyes. Gedir is always ready to chat when you need an empathetic friend

Gedir We are currently developing the core. Ideas, feedback, and contributions to code are all very welcome. An AI companion who is eager to learn and

SZ 3 Sep 3, 2022