Code Monkey home page Code Monkey logo

sample-spring-kafka-microservices's Introduction

Microservices with Spring Boot and Kafka Demo Project Twitter

CircleCI

SonarCloud Bugs Coverage Lines of Code

Articles

This repository is used as the example for the following articles:

  1. Distributed Transactions in Microservices with Kafka Streams and Spring Boot - how to implement distributed transaction based on the SAGA pattern with Spring Boot and Kafka Streams
  2. Deep Dive into Saga Transactions with Kafka Streams and Spring Boot - how to implement distributed transaction based on the SAGA pattern with Spring Boot and fully Kafka Streams KStream and KTable. You need to switch to the streams-full branch.

Description

There are three microservices:
order-service - it sends Order 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 the Order price
stock-service - it performs local transaction on the store basing on number of products in the Order

Here's the diagram with our architecture:

image

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

Running on Docker locally

You can easily run all the apps on Docker with Spring Boot support for (a) Testcontainers (b) Docker Compose

(a) For Testcontainers Go to the order-service directory and execute:

$ mvn clean spring-boot:test-run

Then go to the payment-service directory and execute:

$ mvn clean spring-boot:test-run

Finally go to the stock-service directory and execute:

$ mvn clean spring-boot:test-run

You will have three apps running with a single shared Kafka running on Testcontainers.

(b) For Docker Compose First build the whole project and images with the following command:

$ mvn clean package -DskipTests -Pbuild-image

Then, you can go to the one of available directories: order-service, payment-service or stock-service and execute:

$ mvn spring-boot:run

You start your app and have Kafka and two other containers started with Docker Compose.

sample-spring-kafka-microservices's People

Contributors

piomin avatar renovate[bot] avatar

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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sample-spring-kafka-microservices's Issues

Add License

You have done cool work.

I would like to fork your project and use that for my learning and enhance it, but I cannot use due to missing license. I will provide credits to your blogpost.

Github says missing license does not allow me to use your code as a base.

If you willing to let me use the code, add license using this guide.
I'd do it for you, but I have no clue what type of license you would like to have. :)

Thank you!

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.


Warning

Renovate failed to look up the following dependencies: Failed to look up docker package sample-spring-kafka-microservices/order-service, Failed to look up docker package sample-spring-kafka-microservices/payment-service, Failed to look up docker package sample-spring-kafka-microservices/stock-service, Failed to look up maven package pl.piomin:base-domain.

Files affected: docker-compose.yml, order-service/docker-compose.yml, payment-service/docker-compose.yml, stock-service/docker-compose.yml, order-service/pom.xml, payment-service/pom.xml, stock-service/pom.xml


This repository currently has no open or pending branches.

Detected dependencies

circleci
.circleci/config.yml
  • cimg/openjdk 21.0.2
  • cimg/openjdk 21.0.2
  • maven 1.4.1
docker-compose
docker-compose.yml
  • sample-spring-kafka-microservices/order-service 1.0-SNAPSHOT
  • sample-spring-kafka-microservices/payment-service 1.0-SNAPSHOT
  • sample-spring-kafka-microservices/stock-service 1.0-SNAPSHOT
order-service/docker-compose.yml
  • sample-spring-kafka-microservices/payment-service 1.0-SNAPSHOT
  • sample-spring-kafka-microservices/stock-service 1.0-SNAPSHOT
payment-service/docker-compose.yml
  • sample-spring-kafka-microservices/order-service 1.0-SNAPSHOT
  • sample-spring-kafka-microservices/stock-service 1.0-SNAPSHOT
stock-service/docker-compose.yml
  • sample-spring-kafka-microservices/payment-service 1.0-SNAPSHOT
  • sample-spring-kafka-microservices/order-service 1.0-SNAPSHOT
maven
base-domain/pom.xml
order-service/pom.xml
  • org.springframework.boot:spring-boot-starter-parent 3.2.5
  • org.springdoc:springdoc-openapi-ui 1.8.0
  • pl.piomin:base-domain 1.0-SNAPSHOT
  • org.testcontainers:kafka 1.19.7
  • com.google.cloud.tools:jib-maven-plugin 3.4.2
payment-service/pom.xml
  • org.springframework.boot:spring-boot-starter-parent 3.2.5
  • pl.piomin:base-domain 1.0-SNAPSHOT
  • net.datafaker:datafaker 2.1.0
  • org.testcontainers:kafka 1.19.7
  • com.google.cloud.tools:jib-maven-plugin 3.4.2
pom.xml
  • org.jacoco:jacoco-maven-plugin 0.8.12
stock-service/pom.xml
  • org.springframework.boot:spring-boot-starter-parent 3.2.5
  • pl.piomin:base-domain 1.0-SNAPSHOT
  • org.testcontainers:kafka 1.19.7
  • com.google.cloud.tools:jib-maven-plugin 3.4.2

  • Check this box to trigger a request for Renovate to run again on this repository

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.