ddd-cqrs-4-java-example
Example applications that use ddd-4-java and cqrs-4-java libraries and an EventStore to store the events (Event Sourcing).
Components
Shared
Common code for all demo applications (commands, events, value objects and utilities). More...
Aggregates
DDD related code for all demo applications (aggregates, entities and business exceptions). More...
Java SE + CDI
Two standalone applications (Command & Query) using CDI for dependency injection. More...
Quarkus
Two web applications (Command & Query) based on Quarkus. More...
Spring Boot
Two web applications (Command & Query) based on Spring Boot. More...
Getting started
Prerequisites
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)
Or simply use the lubuntu-developer-vm that has already everything installed. Then execute the following steps:
- Download and install the 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 small 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)
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
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 and one query microservice.
Test
- Open http://localhost:2113/ to access the event store UI (User: admin / Password: changeit)
- 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"}
Stop Event Store and Maria DB and clean up
- Stop Docker Compose (Ubuntu shortcut = ctrl c)
- Remove Docker Compose container
docker-compose rm