"'Capture all changes to an application state as a sequence of events' is what Martin Fowler said about Event Sourcing in 2005 and what is the starting point into that topic for this talk.
I will demonstrate how you can store events using Akka Persistence and then distribute them via AWS to be consumed by your other services.
An event based architecture has lots of technical and organisational benefits for your development team. It can be a huge gain for your development process, but can also be difficult to implement as there are lots of challenges.
I will discuss the good as well as the bad things and provide solutions to overcome common pitfalls and aforementioned challenges."
10. A PersistentActorclass represents one DDD
aggregate.
class TimeEntryAggregate(id: String) extends PersistentActor{
...
override def persistenceId: String = s"time-entry-$id"
...
}
11. A PersistentActorreceives commands and
persists events.
case class CreateTimeEntry(
begin: DateTime,
end: DateTime
)
case class TimeEntryCreated(
begin: DateTime,
end: DateTime,
sequenceNr: Long
)
12. A PersistentActorreceives commands and
persists events.
class TimeEntryAggregate(id: String) extends PersistentActor{
...
override def receiveCommand: Receive =
case CreateTimeEntry(start, end) =>
val event = TimeEntryCreated(start,end, lastSequenceNr + 1)
persist(event){e =>
// update internal state
// here we go after the event is persisted
}
}
...
}
13. A PersistentActorrecovers from the journal
class TimeEntryAggregate(id: String) extends PersistentActor{
...
override def receiveRecover: Receive = {
case TimeEntryCreated(start,end) => // update internal state
}
...
}
32. EVENT SCHEMA EVOLUTION
adding a field to an event type,
remove or rename field in event type,
remove event type,
split event into multiple smaller events.
34. Then something within our schema changes
case class TimeEntryCreated(
...
description: String
...
)
and we will have fun with that one
{
"id" : "123456",
"begin" : "2016-09-01 12:00:00",
"end" : "2016-09-01 12:15:00",
"timeEntryUserId" : "00000000-0000-0000-0000-000000000000",
"userId" : "00000000-0000-0000-0000-000000000000"
}