Skip to content

adamroddy/eventsource

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Event Source Library

This is a small library for working with Event Sourced aggregates and events. It provides functionality around process, querying, etc., but leaves it up to implementations to deal with the persistence specifics (e.g. using Postgres versus Redis, SpringTemplate versus JOOQ).

Usage

Using this library in your gradle build

Add this repo to your .gradle build file

repositories {
    ...
    maven { url "https://dl.bintray.com/thirdchannel/EventSource/" }
}

Then add this to your dependencies

dependencies {
    ...
    compile 'com.thirdchannel:eventsource:0.2.0'
}

What is Event Sourcing?

TODO, but see:

Plus some self promotion:

Key Terms: Aggregates, Events, Snapshots

Aggregate

An Aggregate represents the 'container' or root for a stream of Events. Aside from the properties defined within the interface, all implementation properties should be transient (e.g. not saved directly to the database along with the aggregate). At least, in the 'pure' form of ES. It's fully possible when using this library to create several services around each of your intended Aggregates, which know how to persist specific attributes to the database. One such approach is to use multi-table inheritance to subclass several Aggregates off of some base Aggregate, each

Event

An Event represents a single atomic unit of state change for an Aggregate. It represents something successful that occurred within our system against an Aggregate.

Snapshot

A Snapshot is exactly what it sounds like, a moment-in-time recording of the state of an Aggregate. These Snapshots are used as a starting point for rebuilding the state of an Aggregate without having to process a potentially unwieldy number of events.

Working with this Library

The basic design structure is as follows:

  • Each Aggregate in your system operated on by a dedicated 'EventSourceService'. This is fine if you have only one Aggregate in your system (Microservices, anyone?), but can become cumbersome in a system with multiple Aggregates.
  • Each EventSourceService is backed by a dedicated AggregateService and EventService. These are essentially DAO classes that know only how to CR (No Update or Delete!... well, the AggregateService does update the revision).
  • The EventSourceService utilizes the Aggregate and Event Services and performs the basic ES operations: processing new events, loading an Aggregate to any point in time (most often will be 'Current'), handling Event Serialization and De-Serialization.

Note: I'm not super pleased with the current design and naming; it's subject to change. The goal was to 'hide' the AggregateService and EventService behind a parent Object / API layer, but in practice users tend to want to build queries into the AggregateService directly and access that directly, circumventing the ESService.

Current Serialization Mechanism

An Event Class should mark any data that should be persisted as part of the event with the @EventData annotation. The default mechanism will take those properties and serialize them to JSON using Groovy's JsonBuilder. When pulling events from the database, it will use Groovy's JsonSlurper. This logic is contained within JsonBuilderEventSerializer.

This behavior can be overwritten by implementing your own EventSerializer and calling setEventSerializer on an instance of EventSourceService.

Releasing to Bintray

gradle -DRELEASE_SCOPE=${SCOPE} \
    -Prelease.stage=final \
    -Prelease.scope=${SCOPE} \
    clean build release bintrayUpload

where SCOPE is one of

  • MAJOR
  • MINOR
  • PATCH

TODO:

  • cleanup apis on service to force more through EventSourceService

About

A small library for working with Event Source objects

Resources

Stars

0 stars

Watchers

1 watching

Forks

Packages

 
 
 

Contributors

Languages

  • Groovy 100.0%