Giter VIP home page Giter VIP logo

cqrs-eventsourcing-kafka's Introduction

CQRS and Event Sourcing Implementation with Kafka and MySQL (JBDC)

Introduction

The aim of this small project is to illustrate the possibility of applying CQRS, Domain-Driven Design and Event Sourcing in a simple way, enabling Reactive architecture and leveraging Kafka as a distributed message broker

See: https://speakerdeck.com/vgoldin/es-and-kafka

Structure

Module Purpose
services-core core marker interfaces shared between all other modules
services-infrastructure-eventstore multiple event store implementations (JDBM 2.0 and MySQL JDBC)
services-infrastructure-messaging event publisher and command listener implementation with Kafka
services-intentoryitem-schema json-schema's of all the events and commands used in API and Domain services
services-inventoryitem-api API micro-service, exposing RESTfull API, creating Projectin with Hazelcast and dispatching commands to Kafka
services-inventoryitem-domain Domain micro-service, encapsulating Aggregate Root, handling commands and publishing events

Pre-Requisities

  • JDK 1.8
  • Maven 3.3.x
  • (optional) Docker (for Kafka)

Building

mvn clean install

Running Services

Docker Compose

docker-compose build
docker-compose up -d

Standalone

Kafka

docker run -p 2181:2181 -p 9092:9092 --env ADVERTISED_HOST=127.0.0.1 --env ADVERTISED_PORT=9092 spotify/kafka

API Micro-Service

cd services-inventoryitem-api/target
java -jar services-inventoryitem-api-1.0-SNAPSHOT.jar server classes/application-local.yml

Domain Micro-Service

with local jdbm database

cd services-inventoryitem-domain/target
java -jar services-inventoryitem-domain-1.0-SNAPSHOT.jar server classes/application.yml

with MySQL running on 127.0.0.1:3306 (see docker-compose.yml)

cd services-inventoryitem-domain/target
java -jar services-inventoryitem-domain-1.0-SNAPSHOT.jar server classes/application-jdbc.yml

Exposed APIs

GET     /inventory-items (io.plumery.inventoryitem.api.resources.InventoryItemResource)
POST    /inventory-items (io.plumery.inventoryitem.api.resources.InventoryItemResource)
GET     /inventory-items/events.stream (io.plumery.inventoryitem.api.resources.InventoryItemResource)
PUT     /inventory-items/{id} (io.plumery.inventoryitem.api.resources.InventoryItemResource)
POST    /inventory-items/{id}/deactivate (io.plumery.inventoryitem.api.resources.InventoryItemResource)

Swagger API

http://localhost:9901/swagger.json

Replaying Projection

  • Download and unzip Kafka
  • Change to KAFKA_HOME
  • Stop API Micro-Service
  • Execute the following command:
./bin/kafka-streams-application-reset.sh --application-id InventoryItemsDenormalizationApplication \
                                      --input-topics InventoryItem \
                                      --bootstrap-servers localhost:9092 \
                                      --zookeeper localhost:2181

TODO

  • Get rid of ID.class
  • Generate all the events and commands from JSON schema
  • Implement UI Micro-Service

cqrs-eventsourcing-kafka's People

Contributors

vgoldin avatar dependabot[bot] avatar

Watchers

James Cloos 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.