Documentation ¶
Overview ¶
Package evt defines an interface for plain event sourcing and some generic event processors.
Event sourcing as a concept can be interpreted in various ways. Daql uses mostly 'dump' events, that have generic create, update or delete commands. It can be used for more specific events, those however must resolve to a sequence of generic events. Events have one central and authoritative ledger, that assigns a revision, and with that order to all events.
Each event has a topic, key and command string and optional a argument map. Usually the topic refers to record model name and the key to its primary key as string. The string key allows models with uuid, integer and other character typed keys to share a ledger.
Custom commands have more meaningful names, validation and implementations. They must resolve to one or more generic events to allow a simple and consistent interface for backends.
A ledger is a strictly ordered sequence of events and can be used to recreate a state at a revision. Users publish one or more events as a transaction. The events are resolved, validated and then assigned a revision and audit id and then written to the ledger. A revision is a timestamp with millisecond granularity. It is usually the arrival time of the event but cannot be before the latest applied revision in the persisted ledger. Every transaction generates an audit log entry that has additional information about the user, creation and arrival time and a map of extra information.
To backup and restore both audit and event log are required, as well as other date not covered by the event system.
Servers usually update the latest state of the ledger in the same transaction that applies the event to the ledger. This allows us to avoid event aggregates and materialized view consistency for most operations. We might at some point introduce stateless topics, that have their only persistent representation in the ledger.
Satellite should be able to persist transactions failed due to recoverable errors like network outage for later reconciliation and may serve their clients the projected state of the ledger where appropriate.
Index ¶
- func CollectAll(evs []*Event) map[Sig][]*Event
- func NextRev(last, rev time.Time) time.Time
- type Action
- type Audit
- type ByID
- type ByRev
- type Detail
- type Event
- type HistFunc
- type HistReq
- type HistRes
- type Ledger
- type MetaFunc
- type MetaReq
- type MetaRes
- type PubFunc
- type PubReq
- type PubRes
- type Publisher
- type Replicator
- type Sig
- type SubFunc
- type SubReq
- type SubRes
- type Subscriber
- type Subscribers
- func (subs *Subscribers) Bcast(from hub.Conn, rev time.Time)
- func (subs *Subscribers) Btrig(from hub.Conn)
- func (subs *Subscribers) Show(c hub.Conn, evs []*Event) (sender *Subscriber)
- func (subs *Subscribers) Stop()
- func (subs *Subscribers) Sub(c hub.Conn, ws []Watch) *Subscriber
- func (subs *Subscribers) Unsub(c hub.Conn, ws []Watch)
- type Trans
- type UnsFunc
- type UnsReq
- type UnsRes
- type Update
- type Watch
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CollectAll ¶
Types ¶
type Action ¶
Action is an unpublished event represented by a command string and argument map. It usually is a data operation on a record identified by a topic and primary key.
type Detail ¶
type Detail struct { Created time.Time `json:"created,omitempty"` Arrived time.Time `json:"arrived,omitempty"` Acct [16]byte `json:"acct,omitempty"` Extra *lit.Dict `json:"extra,omitempty"` }
Detail holds extra information for audits and translations.
type Ledger ¶
type Ledger interface { // Rev returns the latest event revision or the zero time. Rev() time.Time Project() *dom.Project // Events returns the ledger events filtered by the given expression and parameters. Events(whr exp.Dyn, param lit.Lit) ([]*Event, error) }
Ledger abstracts over the event storage. It allows to access the latest revision and query events. Ledger implemetations are usually not thread-safe unless explicitly documented.
type Replicator ¶
Replicator is a ledger that can replicate events.
type Subscriber ¶
func (*Subscriber) Accept ¶
func (s *Subscriber) Accept(ev *Event) bool
type Subscribers ¶
type Subscribers struct {
// contains filtered or unexported fields
}
func NewSubscribers ¶
func NewSubscribers() *Subscribers
func (*Subscribers) Bcast ¶
func (subs *Subscribers) Bcast(from hub.Conn, rev time.Time)
Bcast sends all buffered events up to revision rev out to subscribers.
func (*Subscribers) Btrig ¶
func (subs *Subscribers) Btrig(from hub.Conn)
Btrig trigger fires a delayed, de-duped broadcast request with header _bcast.
func (*Subscribers) Show ¶
func (subs *Subscribers) Show(c hub.Conn, evs []*Event) (sender *Subscriber)
func (*Subscribers) Stop ¶
func (subs *Subscribers) Stop()
func (*Subscribers) Sub ¶
func (subs *Subscribers) Sub(c hub.Conn, ws []Watch) *Subscriber