Documentation ¶
Overview ¶
Package eventsourcing provides an implementation of saga.Persister that persists saga instances as a stream of events with optional snapshots.
Index ¶
Constants ¶
const DefaultSnapshotFrequency saga.Revision = 1000
DefaultSnapshotFrequency is the default number of revisions to allow between storing snapshots.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Persister ¶
type Persister struct { MessageStore messagestore.Store Snapshots SnapshotRepository SnapshotFrequency saga.Revision }
Persister is an implementation of saga.Persister that stores saga instances using event-sourcing semantics.
The saga data MUST implement saga.EventedData.
func (*Persister) BeginUnitOfWork ¶
func (p *Persister) BeginUnitOfWork( ctx context.Context, sg saga.Saga, tx persistence.Tx, s ax.Sender, id saga.InstanceID, ) (saga.UnitOfWork, error)
BeginUnitOfWork starts a new unit-of-work that modifies a saga instance.
If the saga instance does not exist, it returns a UnitOfWork with an instance at revision zero.
type Recorder ¶
Recorder is an implementation of ax.Sender that records published events in memory.
type SnapshotRepository ¶
type SnapshotRepository interface { // LoadSagaSnapshot loads the latest available snapshot from the store. // // It returns an error if a snapshot of this instance is found, but belongs to // a different saga, as identified by pk, the saga's persistence key. LoadSagaSnapshot( ctx context.Context, tx persistence.Tx, pk string, id saga.InstanceID, ) (i saga.Instance, ok bool, err error) // SaveSagaSnapshot saves a snapshot to the store. // // The implementation may return an error if a snapshot for this instance // belongs to a different saga, as identified by pk, the saga's persistence // key. SaveSagaSnapshot( ctx context.Context, tx persistence.Tx, pk string, i saga.Instance, ) error // DeleteSagaSnapshots deletes any snapshots associated with a saga instance. // // The implementation may return an error if snapshots for this instance // belongs to a different saga, as identified by pk, the saga's persistence // key. DeleteSagaSnapshots( ctx context.Context, tx persistence.Tx, pk string, id saga.InstanceID, ) error }
SnapshotRepository is an interface for loading and saving snapshots of eventsourced saga data.