2021-09-04 15:56:28 +02:00
2019-12-26 10:54:44 +01:00
2020-12-20 13:53:47 +01:00
2019-12-29 10:03:31 +01:00
2019-12-31 12:21:43 +01:00
2020-12-20 13:53:47 +01:00
2019-04-23 16:40:49 +02:00
2019-12-26 10:54:44 +01:00
2019-12-26 10:54:44 +01:00
2021-09-04 15:56:28 +02:00
2019-12-29 10:48:27 +01:00

ddd-cqrs-4-java-example

Example microservices that use ddd-4-java and cqrs-4-java libraries and an EventStore to store the events (Event Sourcing). Supports Quarkus and Spring Boot.

Java Development Kit 11

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

Option 1: Install everything yourself

Make sure you have the following tools installed/configured:

Option 2: Use lubuntu-developer-vm

The lubuntu-developer-vm has already (almost) everything installed. You only need to execute the following steps:

  1. Download and install the lubuntu-developer-vm as described
  2. OPTIONAL: Change memory of VM to 6 GB (instead of 4 GB default) if you want to create a native image with GraalVM
  3. Start the VM and login (developer / developer)
  4. Open a console (Shortcut = ctrl alt t)
  5. Run a script that finalizes the setup of the developer virtual machine
    bash <(curl \
    -s https://raw.githubusercontent.com/fuinorg/ddd-cqrs-4-java-example/master/setup-lubuntu-developer-vm.sh)   
    
  6. Reboot
    reboot
    

Clone and install project

  1. Open a console (Ubuntu shortcut = ctrl alt t)
  2. Clone the git repository
    git clone https://github.com/fuinorg/ddd-cqrs-4-java-example.git
    
  3. 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

  1. Open a console (Ubuntu shortcut = ctrl alt t)
  2. 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 command microservice and one query microservice - You can mix Quarkus & Spring Boot!

Quarkus Microservices

Module
Command Overview
Query Overview

Spring Boot Microservices

Module
Command Overview
Query Overview

Test

  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
  3. Open a console (Ubuntu shortcut = ctrl alt t)
  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 console should show something like
    Update aggregate: id=PERSON 84565d62-115e-4502-b7c9-38ad69c64b05, version=-1, nextVersion=0
    
    Query console should show something like
    PersonCreatedEventHandler ... Handle PersonCreatedEvent: Person 'Peter Parker' was created
    
  5. Refreshing http://localhost:8080/persons should show
    [{"id":"84565d62-115e-4502-b7c9-38ad69c64b05","name":"Peter Parker"}]
    
  6. Opening http://localhost:8080/persons/84565d62-115e-4502-b7c9-38ad69c64b05 should show
    {"id":"84565d62-115e-4502-b7c9-38ad69c64b05","name":"Peter Parker"}
    
  7. 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
    
Description
Example Java DDD/CQRS/Event Sourcing microservices with Quarkus, Spring Boot and EventStore from Greg Young.
Readme 1.2 MiB
Languages
Java 99.2%
HTML 0.8%