Table of contents
Open Table of contents
Description
This project demonstrates how to build an app that uses CQRS (Command Query Responsibility Segregation) and Event Sourcing patterns using Kotlin, Ktor, Akka, and Cassandra.
It implements hotel reservation management functionality with separate commands for creating, updating, and deleting reservations, along with querying operations to fetch individual or all reservations.
Source code can be found on GitHub.
Actors interaction
Running locally
- Clone the repository
git clone https://github.com/martishin/cqrs-akka-kotlin-example.git
cd cqrs-akka-kotlin-example
- Start the Cassandra database
docker-compose up cassandra
- Build and run the application
./gradlew run
- The server will be available at http://localhost:8080.
Making API Requests
You can interact with the system using the following curl commands. You can also execute these REST calls using Postman.
- Create a reservation
curl -X POST http://localhost:8080/reservations \
-H "Content-Type: application/json" \
-d '{
"guestId": "guest123",
"startDate": "2023-11-01",
"endDate": "2023-11-05",
"roomNumber": 101
}'
- Update the reservation
curl -X PUT http://localhost:8080/reservations/{confirmationNumber} \
-H "Content-Type: application/json" \
-d '{
"startDate": "2023-12-01",
"endDate": "2023-12-05",
"roomNumber": 102
}'
- Delete the reservation
curl -X DELETE http://localhost:8080/reservations/{confirmationNumber}
- Get all reservations
curl -X GET http://localhost:8080/reservations
- Get the reservation
curl -X GET http://localhost:8080/reservations/{confirmationNumber}
Testing
Run tests
./gradlew test
Technologies Used
- Kotlin and coroutines - modern JVM language with concise syntax and safety features
- Akka - actor-based concurrency framework
- Ktor - Kotlin framework for building asynchronous servers and clients
- Apache Cassandra - distributed NoSQL database for scalability and high availability
- Gradle - build automation tool