akbashev/cluster-event-sourcing
An event sourcing framework implementation for Swift distributed [Cluster System](https://github.com/apple/swift-distributed-actors).
Usage
Documentation: TODO
- Currently there is no default store providers, so you need to create one and conform to
EventStoreprotocol. This could be any class, actor and etc. - Install plugins.
ClusterJournalPluginwraps store into singleton, so singleton plugin also should be added (and order is important!).
let node = await ClusterSystem("simple-node") {
$0.plugins.install(plugin: ClusterSingletonPlugin())
$0.plugins.install(
plugin: ClusterJournalPlugin { _ in
SomeStore()
}
)
}- Make distributed actor
EventSourcedand define thehandleEvent(_:)function. Register the actor with the journal ininit:
distributed actor SomeActor: EventSourced {
// Some custom events for actor
enum Event {
case doSomething
}
distributed func doSomething() async throws {
try await self.emit(event: .doSomething)
}
distributed func handleEvent(_ event: Event) {
switch event {
case .doSomething:
// update state
}
}
init(actorSystem: ClusterSystem, persistenceId: PersistenceID) async throws {
self.actorSystem = actorSystem
try await actorSystem.journal.register(actor: self, with: persistenceId)
}
}Package Metadata
Repository: akbashev/cluster-event-sourcing
Stars: 3
Forks: 0
Open issues: 0
Default branch: main
Primary language: swift
License: Apache-2.0
README: README.md