Giter Club home page Giter Club logo

ddd-cqrs-4-java-example's Introduction

ddd-cqrs-4-java-example

Example Java DDD/CQRS/Event Sourcing microservices with Quarkus, Spring Boot and the EventStore from Greg Young. The code uses the lightweight ddd-4-java and cqrs-4-java libaries. No special framework is used except the well known JEE/Spring standards.

Java Development Kit 11 Apache Build Status

Background

This application shows how to implement DDD, CQRS and Event Sourcing without a DDD/CQRS framework. It uses just a few small libraries in addition to standard web application frameworks like Quarkus and Spring Boot.

If you are new to the DDD/CQRS topic, you can use these mindmaps to find out more:

Here is an overview of how such an application looks like:

Overview

Components

Getting started

Prerequisites

Make sure you have the following tools installed/configured:

Clone and install project

  1. Clone the git repository
    git clone https://github.com/fuinorg/ddd-cqrs-4-java-example.git
    
  2. Change into the project's directory and run a Maven build
    cd ddd-cqrs-4-java-example
    ./mvnw install
    
    Be patient - This may take a while (~5 minutes) as all dependencies and some Docker images must be downloaded and also some integration tests will be executed.

Start Event Store and Maria DB (Console window 1)

Change into the project's directory and run Docker Compose

cd ddd-cqrs-4-java-example
docker-compose up

Start command / query implementations

Start one query service and then one command service. You can mix Quarkus & Spring Boot if you want to!

Quarkus Microservices

Quarkus Query Service (Console window 2)
  1. Start the Quarkus query service:
    cd ddd-cqrs-4-java-example/quarkus/query
    ./mvnw quarkus:dev
    
  2. Opening http://localhost:8080/ should show the query welcome page

For more details see quarkus/query.

Quarkus Command Service (Console window 3)
  1. Start the Quarkus command service:
    cd ddd-cqrs-4-java-example/quarkus/command
    ./mvnw quarkus:dev
    
  2. Opening http://localhost:8081/ should show the command welcome page

For more details see quarkus/command.

Spring Boot Microservices

Spring Boot Query Service (Console window 2)
  1. Start the Spring Boot query service:
    cd ddd-cqrs-4-java-example/spring-boot/query
    ./mvnw spring-boot:run
    
  2. Opening http://localhost:8080/ should show the query welcome page

For more details see spring-boot/query.

Spring Boot Command Service (Console window 3)
  1. Start the Spring Boot command service:
    cd ddd-cqrs-4-java-example/spring-boot/command
    ./mvnw spring-boot:run
    
  2. Opening http://localhost:8081/ should show the command welcome page

For more details see spring-boot/command.

Verify projection and query data

  1. Open http://localhost:2113/ to access the event store UI (User: admin / Password: changeit) You should see a projection named "qry-person-stream" when you click on "Projections" in the top menu.
  2. Opening http://localhost:8080/persons should show an empty JSON array

Execute a test command (Console window 4)

Change into the demo directory and execute a command using cURL (See shell script and command)

cd ddd-cqrs-4-java-example/demo
./create-person-command.sh

Command service (Console window 3) should show something like

Update aggregate: id=PERSON 84565d62-115e-4502-b7c9-38ad69c64b05, version=-1, nextVersion=0

Query service (Console window 2) should show something like

PersonCreatedEventHandler ... Handle PersonCreatedEvent: Person 'Peter Parker' was created

Verify the query data was updated

  1. Refreshing http://localhost:8080/persons should show
    [{"id":"84565d62-115e-4502-b7c9-38ad69c64b05","name":"Peter Parker"}]
  2. Opening http://localhost:8080/persons/84565d62-115e-4502-b7c9-38ad69c64b05 should show
    {"id":"84565d62-115e-4502-b7c9-38ad69c64b05","name":"Peter Parker"}
  3. The event sourced data of the person aggregate could be found in a stream named PERSON-84565d62-115e-4502-b7c9-38ad69c64b05

Stop Event Store and Maria DB and clean up

  1. Stop Docker Compose (Ubuntu shortcut = ctrl c)
  2. Remove Docker Compose container
    docker-compose rm
    

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.