My implementation of Reactive Stock Trader system (Portfolio, Broker, Wire Transfers Services) in Scala.
Tools - Lagom (Play, Akka, Cassandra and Kafka), Vue.js (for UI), Kubernetes
Patterns - Event Sourcing, CQRS
Architecture - Interface, gateway, services
Integration - Point to Point, streaming, pub/sub
Reactive in practice: A complete guide to event-driven systems development in Java
Java Implementation of Reactive Stock Trader by RedElastic
- Unit 1: Introduction: event storming the 'stock trader' domain
- Unit 2: Prototyping the UI and UI integration patterns
- Unit 3: Translating the domain model to service APIs
- Unit 4: Concurrency, parallelism and asynchrony
- Unit 5: Event sourcing
- Unit 6: CQRS - Write side (commands and state)
- Unit 7: CQRS - Read side (queries and views)
- Unit 8: Integration patterns for transactions
- Unit 9: Microservice integration patterns
- Unit 10: Streaming data
- Unit 11: Deploying and monitoring reactive systems in the cloud
- Unit 12: Recap and conclusion
The following will help you get set up in the following contexts:
- Local development
- Deployment to local Kubernetes (using Minikube)
- Interactions (UI, command line)
- Install Java 8 SDK
- Install sbt (
brew install sbt
on Mac)
This project has been generated by the lagom/lagom-scala.g8 template. For instructions on running and testing the project, see https://www.lagomframework.com/get-started-scala.html.
Running Lagom in development mode is simple. Start by launching the backend services using sbt
.
sbt runAll
The Gateway exposes an API to the frontend on port 9100.
For instructions on how to deploy Reactive Stock Trader to Kubernetes, you can find the deployment instructions and Helm Charts for Kafka and Cassandra here: https://github.com/RedElastic/reactive-stock-trader/tree/master/deploy
The UI is developed in Vue.js. You'll need to have Node.js and npm installed and then follow the instructions below.
Project setup and launching for development:
npm install
npm run serve
This will launch the UI on localhost:8080 for development. You can then use the UI to interact with the Lagom system.
Testing / debugging:
- Run your tests:
npm run test
- Lints and fixes files:
npm run lint
Reactive Stock Trader uses Rollbar for debugging purposes. In order to make use of Rollbar:
- copy
config.env
to.env.local
- sign up at Rollbar and create an access token
- change
VUE_APP_ROLLBAR_ACCESS_TOKEN
to your token in.env.local
Visit Environment Variables and Modes and https://rollbar.com for more details.
For additional Vue configuration information, see Configuration Reference.
If you would like to test the backend without installing the UI, you can use the following command line information to help.
The jq
command line tool for JSON is very handy for pretty printing JSON responses, on Mac this can be installed with brew install jq
.
Create a new portfolio named "piggy bank savings":
PID=$(curl -X POST http:/localhost:9000/api/portfolio -F name="piggy bank savings" | jq -r .portfolioId); echo $PID
Place an order:
curl -X POST http://localhost:9000/api/portfolio/$PID/order -F symbol=RHT -F shares=10 -F order=buy
View the portfolio
curl http://localhost:9000/api/portfolio/$PID | jq .
Transfer funds into the portfolio
curl -X POST http://localhost:9000/api/transfer -F amount=20000 -F sourceType=savings -F sourceId=123 -F destinationType=portfolio -F destinationId=$PID
PID=$(curl -X POST http:/localhost:9000/api/portfolio -F name="piggy bank savings" | jq -r .portfolioId); echo $PID
curl -X POST http://localhost:9000/api/transfer -F amount=20000 -F sourceType=savings -F sourceId=123 -F destinationType=portfolio -F destinationId=$PID
curl http://localhost:9000/api/portfolio/$PID | jq .
curl -X POST http://localhost:9000/api/portfolio/$PID/order -F symbol=IBM -F shares=10 -F order=buy
curl http://localhost:9000/api/portfolio/$PID | jq .