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).
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:
Components
- Shared - Common code for all demo applications (commands, events, value objects and utilities).
- Aggregates - DDD related code for all demo applications (aggregates, entities and business exceptions).
- Quarkus - Two microservices (Command & Query) based on Quarkus that is the successor of Wildfly Swarm/Thorntail and has CDI, JAX-RS and SmallRye (Eclipse MicroProfile).
- Spring Boot - Two microservices (Command & Query) based on Spring Boot.
- Java SE + CDI - Two standalone applications (Command & Query) using CDI for dependency injection.
Getting started
Prerequisites
Option 1: Install everything yourself
Make sure you have the following tools installed/configured:
- git (VCS)
- Docker CE
- Docker Compose
- OPTIONAL GraalVM
- Hostname should be set in /etc/hosts (See Find and Change Your Hostname in Ubuntu for more information)
⭐ Option 2: Use lubuntu-developer-vm ⭐
The lubuntu-developer-vm has already (almost) everything installed. You only need to execute the following steps:
- Download and install the lubuntu-developer-vm as described
- OPTIONAL: Change memory of VM to 6 GB (instead of 4 GB default) if you want to create a native image with GraalVM
- Start the VM and login (developer / developer)
- Open a console (Shortcut = ctrl alt t)
- 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) - Reboot
reboot
Clone and install project
- Open a console (Ubuntu shortcut = ctrl alt t)
- Clone the git repository
git clone https://github.com/fuinorg/ddd-cqrs-4-java-example.git - Change into the project's directory and run a Maven build
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.
cd ddd-cqrs-4-java-example ./mvnw install
Start Event Store and Maria DB
- Open a console (Ubuntu shortcut = ctrl alt t)
- 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 | ![]() |
| Query | ![]() |
Spring Boot Microservices
| Module | |
|---|---|
| Command | ![]() |
| Query | ![]() |
Test
- 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.
- Opening http://localhost:8080/persons should show an empty JSON array
- Open a console (Ubuntu shortcut = ctrl alt t)
- Change into the demo directory and execute a command using cURL (See shell script and command)
Command console should show something like
cd ddd-cqrs-4-java-example/demo ./create-person-command.shQuery console should show something likeUpdate aggregate: id=PERSON 84565d62-115e-4502-b7c9-38ad69c64b05, version=-1, nextVersion=0PersonCreatedEventHandler ... Handle PersonCreatedEvent: Person 'Peter Parker' was created - Refreshing http://localhost:8080/persons should show
[{"id":"84565d62-115e-4502-b7c9-38ad69c64b05","name":"Peter Parker"}] - Opening http://localhost:8080/persons/84565d62-115e-4502-b7c9-38ad69c64b05 should show
{"id":"84565d62-115e-4502-b7c9-38ad69c64b05","name":"Peter Parker"} - 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
- Stop Docker Compose (Ubuntu shortcut = ctrl c)
- Remove Docker Compose container
docker-compose rm
Description
Example Java DDD/CQRS/Event Sourcing microservices with Quarkus, Spring Boot and EventStore from Greg Young.
Languages
Java
99.2%
HTML
0.8%




