The purpose of this repository is to provide a reference implementation for a sample application that demonstrates the usage of Apache Kafka. The detailed description for the application architecture and the styles underpinning it, please check my blog on Ghost.io
The implementation adapts the following architectural styles:
- Domain Driven Design
- Command Query Responsibility Segregation
- Event Sourcing
The application uses the following set of light-weight technologies and frameworks:
- Apache Kafka for Messaging
- MongoDB for Persistence
- Spring MVC for REST Services
- Spring Data for Data Access Objects
- Spring Boot for Bootstrapping and Boilerplates
Before running the above application, you'll need to install the following on your machine:
- Maven 3.0.3 or later
- MongoDB, I used v3.2 at the time of this implementation
- Apache Kafka v0.9 or later
If you have a Mac OS, you can install the above components using Homebrew. The following commands install the above:
$ brew install maven
$ brew install kafka
$ brew install mongodb
Once you have the above software installed, you can run the application in the following order:
- Go to the root directory of the application and type:
mvn clean install
- Start the
application-api
project which is the entry point for REST URL's of the commands. You can start it by navigating to its subdirectory and type:mvn spring-boot:run
- Start the
application
project which contains the domain logic and event sourcing. You can start it by navigating to its subdirectory and type:mvn spring-boot:run
- Start the
query-api
project which represents the query part subscribing to the published events. You can start it by navigating to its subdirectory and type:mvn spring:boot:run
The above steps assume the default settings for Mongo and Kafka. If you could like to change any of those settings, please
navigate to application.properties
file that you'll find under each of the three applications above and then change the proper
values and re-run it again.
The command part can be tested by POSTing a JSON message to the following REST endpoint:
http://localhost:8080/profiles/registrations
and the sample JSON request is:
{
"username": "username",
"email": "[email protected]",
"password": "password"
}
As for the query part, you can test it by GET the following REST endpoint:
http://localhost:9090/profiles
You can also check the messages as it passes through Kafka using the ./topic-console-consumer
utility