Skip to content

akornatskyy/sample-event-sourcing-java

Repository files navigation

Sample Event Sourcing Java

tests

Setup

Create quickstart-events topic.

bin/kafka-topics.sh --create --topic quickstart-events \
  --partitions 4 --bootstrap-server localhost:9092

Open consumer for this topic.

bin/kafka-console-consumer.sh --topic quickstart-events \
  --from-beginning --bootstrap-server localhost:9092

Event Publisher

Run domain-event-publisher to emit UpdateCustomer and ActivateCustomer events.

Transactional Outbox

Supposed to be used with Change Data Capture pattern to emit domain events.

TODO: requires SQL schema and testing.

Subscriber API

Run subscriber-api to access events via HTTP SSE.

Receive all events from the beginning:

curl -v http://localhost:8080/topics/quickstart-events/events

Filter events by event type:

curl -v http://localhost:8080/topics/quickstart-events/events?eventTypes=UpdateCustomer

Request events using a cursor:

curl -v -H "x-last-event-id:MCwx" \
  http://localhost:8080/topics/quickstart-events/events

TODO: filter by tenant-id, multiple topics.

Event Projector

Uses Subscriber API to read events and update local read store. Run domain-event-projector.

TODO: SQL repository implementation.

References