Rapter1990 / cqrs-example

Spring Boot CQRS Example (Docker, Apache Kafka, Zookeeper, MYSQL, MongoDB)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Spring Boot CQRS Example (Docker, Apache Kafka, Zookeeper, MYSQL, MongoDB)

Main Information

📖 Information

  • CQRS (Command Query Responsibility Segregation) is an architectural pattern that separates a system into two parts: one for updating data (commands) and another for reading data (queries).
  • CQRS is implemented in this project with running on Docker and it provides the necessary components to build an event-driven handling with Apache Kafka

Explore Rest APIs

Method Url Description Valid Request Body Valid Request Params Valid Request Params and Body No Valid Request Params and Body
POST /api/v1/openBankAccount Open a Bank Account Info
PUT /api/v1/depositFunds/{id} Deposit Fund to the Account Info
PUT /api/v1/withdrawFunds/{id} Withdraw Fund from Account Info
DELETE /api/v1/closeBankAccount/{id} Close Account Info
GET /api/v1/bankAccountLookup/ Get All Accounts Info
GET /api/v1/bankAccountLookup/{id} Get Account By Id Info
GET /api/v1/bankAccountLookup/byHolder/{account_holder} Get Account By Holder Info
GET /api/v1/bankAccountLookup/withBalance/GREATER_THAN/{value} Get Account By Balance Greather Then Value Info
GET /api/v1/bankAccountLookup/withBalance/LESS_THAN/{value} Get Account By Balance Less Then Value Info
GET /api/v1/restoreReadDb Restore Database By Read Info

Used Dependencies

  • Core
    • Spring
      • Spring Boot
      • Spring Data
        • Spring Data JPA
  • Database
    • Mysql
    • Mongodb
  • Kafka
  • Lombok
  • Docker

Valid Request Body

Open a Bank Account
    http://localhost:5000/api/v1/openBankAccount
    
    {
        "accountHolder" : "Account Holder 1",
        "accountType" : "SAVINGS",
        "openingBalance" : 50.0
    }
    

Valid Request Params

Close Account
    http://localhost:5000/api/v1/closeBankAccount/{id}
    
Get Account By Id
    http://localhost:5001/api/v1/bankAccountLookup/byId/{id}
    
Get Account By Holder
    http://localhost:5001/api/v1/bankAccountLookup/byHolder/{account_holder}
    
Get Account Greather then Value
    http://localhost:5001/api/v1/bankAccountLookup/withBalance/GREATER_THAN/{value}
    
Get Account Less then Value
    http://localhost:5001/api/v1/bankAccountLookup/withBalance/LESS_THAN/{value}
    

Valid Request Params and Body

Deposit Fund to the Account
    http://localhost:5000/api/v1/depositFunds/{id}
    
    {
        "amount" : 150.0
    }
Withdraw Fund from Account
    http://localhost:5000/api/v1/withdrawFunds/{id}
    
    {
        "amount" : 50.0
    }

No Valid Request Params and Body

Get All Accounts
    http://localhost:5001/api/v1/bankAccountLookup/
    
Restore Database By Read
    http:localhost:5000/api/v1/restoreReadDb
    

🔨 Run the App

There are 2 ways to run the app.

Maven

  1. Install mysql in your computer
  2. Install mongodb in your computer
  3. Run only Zookeeper and Apache Kafka from docker-compose.yml file
  4. Download your project from this link https://github.com/Rapter1990/cqrs-example
  5. Go to the project's home directory : cd cqrs-example
  6. Go to the bank-account : cd bank-account
  7. Create a jar file under bank-account directory though this command mvn clean install
  8. Run the project though this command mvn spring-boot:run
  9. Send any request of collection under postman collections folder through Postman
  10. Show data from both mongodb by following all these commands shown below
    -> Open Mongodb Comprass
    -> Create a new connection (mongodb://localhost:27017)
    -> Show data from eventStore collection of bankAccount database
  1. Show data from both mongodb by following all these commands shown below
    -> Open Mysql Workbench
    -> Use default connection
    -> Show data from bank_account table of bankAccount database

Docker Compose

  1. Download your project from this link https://github.com/Rapter1990/cqrs-example
  2. Go to the project's home directory : cd cqrs-example
  3. Go to the bank-account directory : cd bank-account
  4. Run docker-compose though this command docker-compose up --build
  5. Send any request of collection under postman collections folder through Postman
  6. Show data from both mongodb by following all these commands shown below
    -> docker exec -it mongo-container bash
    -> mongosh
    -> show dbs
    -> use bankAccount
    -> show collections
    -> db.eventStore.find({})
  1. Show data from both mysql by following all these commands shown below
    -> docker exec -it mysql-database mysql -uroot -p
    -> Enter password: password defined in database
    -> USE bankAccount
    -> show tables;
    -> SELECT * FROM bank_account;

Screenshots

Click here to show the screenshots of project

Figure 1

Figure 2

Figure 3

Figure 4

Figure 5

Figure 6

Figure 7

Figure 8

Figure 9

Figure 10

About

Spring Boot CQRS Example (Docker, Apache Kafka, Zookeeper, MYSQL, MongoDB)


Languages

Language:Java 99.4%Language:Dockerfile 0.6%