Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
client
mongodb_connect_jars
projections
sagas
scripts
server
shared
LICENSE
Makefile
README.md
docker-compose.yml
lombok.config
pom.xml
runClient.sh
runCombined.sh
runProjections.sh
runSagaActionProcessor.sh
runSagaCoordinator.sh
runServer.sh

README.md

Simple Sourcing - Auction Example

Simple Sourcing is an API for building event sourcing systems where the data is stored in Kafka.

The Auction Example is a multi-module project that demonstrates the logical separation between the various stream processors comprising a typical Simple Sourcing architecture, with each module running in a separate JVM process.

This allows a loosely coupled deployment whereby each component can be scaled independently of each other.

Running the application

From the project's root folder:

  1. Start the backend dependencies in Docker

    docker-compose up
  2. Start the backend applications:

    ./runServer.sh
    ./runSagaActionProcessor.sh
    ./runSagaCoordinator.sh
    ./runProjections.sh
    ./runClient.sh

If you are running the application for the first time the Server and Saga processes should be started first as they create any new Kafka topics, before the Projection and Client services consume from them.

  1. Run the front end in Docker:

    Change to the auction-frontend folder:

    docker-compose up 
  2. Open a web browser at http://localhost:3000

Test locally

If you are using Docker for Mac >= 1.12, Docker for Linux, or Docker for Windows 10, then please add the following lines to /etc/hosts or C:\Windows\System32\Drivers\etc\hosts:

127.0.0.1   zookeeper
127.0.0.1   broker
127.0.0.1   schema_registry
127.0.0.1   connect
127.0.0.1   mongo-express
127.0.0.1   mongo

REST APIs for write side

The example comes with a REST API, the following are supported services

Account aggregate
  • To create an account, do a POST request to URL http://localhost:8080/auction-example/accounts the following is an example
curl -X POST \
  http://localhost:8080/auction-example/accounts \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d '{
	"accountId": "b5023d7f-e45e-44d1-8bc2-c71c77fdc8c5",
	"accountDto": {
		"userName": "Sarah Dubois",
		"funds": 1000.576
	}
}'
  • To update userName of an account, you need to do a PUT request to URL http://localhost:8080/auction-example/accounts/{accountId}
curl -X PUT \
  http://localhost:8080/auction-example/accounts/b5023d7f-e45e-44d1-8bc2-c71c77fdc8c5 \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d '{
	"userName": "Sarah Jones"
}'
  • To add funds to an account, use a POST request to http://localhost:8080/auction-example/{accountId}/funds
curl -X POST \
  http://localhost:8080/auction-example/accounts/b5023d7f-e45e-44d1-8bc2-c71c77fdc8c5/funds \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d '{
	"funds": 1000
}'
  • To reserve funds for an account, use POST request to http://localhost:8080/auction-example/accounts/{accountId}/funds/reservations
curl -X POST \
  http://localhost:8080/auction-example/accounts/b5023d7f-e45e-44d1-8bc2-c71c77fdc8c5/funds/reservations \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d '{
	"reservationId": "f2e12fec-413f-48d8-a64d-2b70811261b4",
	"description": "Reserve funds",
	"amount": 300
}'
  • To cancel a reservation, you would need to use a DELETE request to http://localhost:8080/auction-example/accounts/{accountId}/funds/reservations/{reservationId}

  • To confirm a reservation, you could use a POST request to http://localhost:8080/auction-example/accounts/{accountId}/funds/reservations/{reservationId}

curl -X POST \
  http://localhost:8080/auction-example/accounts/b5023d7f-e45e-44d1-8bc2-c71c77fdc8c5/funds/reservations/f2e12fec-413f-48d8-a64d-2b70811261b4 \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d 250
Auction aggregate
curl -X POST \
  http://localhost:8080/auction \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d '{
	"key": "4701ecba-aed7-4df6-bfeb-6d9e11d36f5c",
	"value": {
		"creator": "Sarah Jones",
		"title": "CBD Hub auction",
		"description": "Auction for the Southern Cross Hub",
		"reservePrice": 2000000
	}
}'
  • To update auction do a PUT request to endpoint http://localhost:8080/auction-example/{auctionId}
curl -X POST \
  http://localhost:8080/auction-example/4701ecba-aed7-4df6-bfeb-6d9e11d36f5c \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d '{
	
		"creator": "Sarah Jones",
		"title": "CBD Hub updated",
		"description": "CBD Hub",
		"reservePrice": 500
	
}'

REST APIs for read side

Once you run script kafka_connect.sh Kafka connector instances will be created to populate Mongo database collections with the projection of aggregates. The following table shows the REST endpoints could be used to view the result of projection saved in Mongodb Please note the base URI for all those endpoints is http://localhost:8080/auction-example/projections

End point Description
/accounts Accounts projection view
/auctions Auctions projection view
/transactions All account transactions (added/canceled/ and confirmed reservations for accounts)
/accounts/{accountId} Account details for account with passed ID
/accounts/{accountId}/transactions All transactions for specified account
You can’t perform that action at this time.