• Stars
    star
    163
  • Rank 231,141 (Top 5 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 5 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Example Java DDD/CQRS/Event Sourcing microservices with Quarkus, Spring Boot and EventStore from Greg Young.

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
    

More Repositories

1

ddd-4-java

Base classes for Domain Driven Design (DDD) with Java
Java
77
star
2

utils4maven

Utilities for Maven development
Java
20
star
3

event-store-commons

Defines a common event store Java interface and provides some adapters (like for Greg Young's event store) and implementations (like in-memory, JPA or file-based).
Java
15
star
4

cqrs-4-java

Base classes for Command Query Responsibility Segregation (CQRS) with Java
Java
13
star
5

org.fuin.dsl.ddd

Xtext based DSL supporting Domain-driven design (DDD)
Xtend
12
star
6

emt-xtext-archetype

Eclipse Maven Tycho XText Archetype
Xtend
10
star
7

utils4j

A small Java library that contains several helpful utility classes.
Java
9
star
8

event-store-maven-plugin

This plugin provides goals that start/stop Greg Young's event store.
Java
6
star
9

srcgen4javassist

A small wrapper for Javassist that can be used to generate source files and bytecode.
Java
6
star
10

javafx-cdi-example

JavaFX with CDI example project
Java
5
star
11

objects4j

A library with common Java types that are mostly immutable value objects.
Java
5
star
12

SrcMixins4J

Source code based mixins for Java
Java
4
star
13

units4j

A home for additional useful unit testing modules for Java.
Java
4
star
14

keycloak-admin-client-wrapper

Small wrapper around the Keycloak Admin Client that simplifies some tasks
Java
4
star
15

ext4logback

Extensions for Logback
Java
3
star
16

atlassian-default-image-awscli

The Atlassian default build environment Docker image for Bitbucket Pipelines plus the AWS Command Line Interface (CLI)
3
star
17

ddd-templates

Xtend based domain-driven design (DDD) code generation templates for use with SrcGen4J
Xtend
3
star
18

code2svg

A minimalistic converter that transforms code into SVG text with syntax highlighting.
Java
3
star
19

srcgen4j-core

Source code generation for Java (Core)
Java
2
star
20

srcgen4j-commons

Source code generation for Java (Commons)
Java
2
star
21

jee-keycloak-microprofile-quickstart

JEE Wildfly Keycloak Microprofile REST Swagger Quickstart
Java
1
star
22

wildfly-swagger-ui

WildFly with Swagger UI Welcome Page Docker image
HTML
1
star
23

commons-vfs2-filters

Apache Commons IO File Filters ported to the Commons Virtual File System (VFS)
Java
1
star
24

srcgen4j-maven

Source code generation for Java (Maven Plugin)
Java
1
star
25

lubuntu-developer-vm

A Vagrant configuration for creating a developer Lubuntu VMware and VirtualBox image
Shell
1
star
26

javafx-cdi-archetype

JavaFX with CDI Project Maven Archetype
Java
1
star
27

sjsm

A simple java send mail command line application
Java
1
star
28

dev-setup-wizard

A JavaFX based wizard for setting up a development environment on a Linux virtual machine (VM)
Java
1
star
29

kickstart4j

A Java Webstart based Installer and Updater.
Java
1
star
30

arquillian-wildfly-docker-example

Arquillian test deployed to a remote Wildfly server running in a Docker container
Java
1
star