/ticket-booking-aecor

Sample application for "Aecor — Purely functional event sourcing in Scala" series.

Primary LanguageScalaApache License 2.0Apache-2.0

Eventsourced ticket bookings with Aecor

This is a sample application for the "Aecor - Purely functional event sourcing in Scala" post series.

Prerequisites

Infrastructure for the app includes postgres and kafka, so you'll need either

  • docker-compose (recommended)
  • or have both postgres and kafka installed locally.

Running (with docker-compose)

  1. Launch infrastructure using compose (in the project folder):
docker-compose up -d
  1. If you are using docker-compose on macOS or Windows you should also forward all ports used in docker-compose.yml file (to be able to reach all Docker containers via localhost address). You can do this via docker-machine CLI or by a script such as docker-machine-port-forwarder:
pf 5432
pf 2181
pf 9092
  1. Run the app
sbt booking/run

Playing around

There are http endpoints you can call

Place booking:
curl --request POST \
  --url http://localhost:9000/clientA/bookings \
  --header 'content-type: application/json' \
  --data '{
	"concertId": "concertA",
	"seats": [
		{
			"row": 1,
			"number": 2
		},
		{
			"row": 1,
			"number": 3
		}
	]
}'
Get client bookings:
curl --request GET \
  --url http://localhost:9000/clientA/bookings
Emulate payment (via kafka message):

Payments are received from another service via PaymentReceived topic, so to emulate a payment we'll need to produce a message:

docker exec -it ticket-booking-aecor_kafka_1 /bin/bash

$KAFKA_HOME/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic PaymentReceived

{"clientId":"clientA", "paymentId":"12345", "bookingId": "<your_booking_id>"}