Documentation ¶
Index ¶
- Variables
- type AppendOption
- type Command
- type Decider
- type Event
- type EventStore
- func (s *EventStore) Append(ctx context.Context, subject string, events []*Event, opts ...AppendOption) (uint64, error)
- func (s *EventStore) Create(config *nats.StreamConfig) error
- func (s *EventStore) Delete() error
- func (s *EventStore) Evolve(ctx context.Context, subject string, model Evolver, opts ...LoadOption) (uint64, error)
- func (s *EventStore) Load(ctx context.Context, subject string, opts ...LoadOption) ([]*Event, uint64, error)
- func (s *EventStore) Update(config *nats.StreamConfig) error
- type Evolver
- type LoadOption
- type Rita
- type RitaOption
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type AppendOption ¶
type AppendOption interface {
// contains filtered or unexported methods
}
AppendOption is an option for the event store Append operation.
func ExpectSequence ¶
func ExpectSequence(seq uint64) AppendOption
ExpectSequence indicates that the expected sequence of the subject sequence should be the value provided. If not, a conflict is indicated.
type Event ¶
type Event struct { // ID of the event. This will be used as the NATS msg ID // for de-duplication. ID string // Time is the time of when the event occurred which may be different // from the time the event is appended to the store. If no time is provided, // the current local time will be used. Time time.Time // Type is a unique name for the event itself. This can be ommitted // if a type registry is being used, otherwise it must be set explicitly // to identity the encoded data. Type string // Data is the event data. This must be a byte slice (pre-encoded) or a value // of a type registered in the type registry. Data any // Metadata is application-defined metadata about the event. Meta map[string]string // Subject is the the subject the event is associated with. Read-only. Subject string // Sequence is the sequence where this event exists in the stream. Read-only. Sequence uint64 }
Event is a wrapper for application-defined events.
type EventStore ¶
type EventStore struct {
// contains filtered or unexported fields
}
EventStore provides event store semantics over a NATS stream.
func (*EventStore) Append ¶
func (s *EventStore) Append(ctx context.Context, subject string, events []*Event, opts ...AppendOption) (uint64, error)
Append appends a one or more events to the subject's event sequence. It returns the resulting sequence number of the last appended event.
func (*EventStore) Create ¶
func (s *EventStore) Create(config *nats.StreamConfig) error
Create creates the event store given the configuration. The stream name is the name of the store and the subjects default to "{name}}.>".
func (*EventStore) Evolve ¶
func (s *EventStore) Evolve(ctx context.Context, subject string, model Evolver, opts ...LoadOption) (uint64, error)
Evolve loads events and evolves a model of state. The sequence of the last event that evolved the state is returned, including when an error occurs.
func (*EventStore) Load ¶
func (s *EventStore) Load(ctx context.Context, subject string, opts ...LoadOption) ([]*Event, uint64, error)
Load fetches all events for a specific subject. The primary use case is to use a concrete subject, e.g. "orders.1" corresponding to an aggregate/entity identifier. The second use case is to load events for a cross-cutting view which can use subject wildcards.
func (*EventStore) Update ¶
func (s *EventStore) Update(config *nats.StreamConfig) error
Update updates the event store configuration.
type LoadOption ¶
type LoadOption interface {
// contains filtered or unexported methods
}
LoadOption is an option for the event store Load operation.
func AfterSequence ¶
func AfterSequence(seq uint64) LoadOption
AfterSequence specifies the sequence of the first event that should be fetched from the sequence up to the end of the sequence. This useful when partially applied state has been derived up to a specific sequence and only the latest events need to be fetched.
type Rita ¶
type Rita struct {
// contains filtered or unexported fields
}
func New ¶
func New(nc *nats.Conn, opts ...RitaOption) (*Rita, error)
New initializes a new Rita instance with a NATS connection.
func (*Rita) EventStore ¶
func (r *Rita) EventStore(name string) *EventStore
func (*Rita) UnpackEvent ¶
UnpackEvent unpacks an Event from a NATS message.
type RitaOption ¶
type RitaOption interface {
// contains filtered or unexported methods
}
RegistryOption models a option when creating a type registry.
func Clock ¶
func Clock(clock clock.Clock) RitaOption
Clock sets a clock implementation. Default it clock.Time.
func ID ¶
func ID(id id.ID) RitaOption
ID sets a unique ID generator implementation. Default is id.NUID.
func TypeRegistry ¶
func TypeRegistry(types *types.Registry) RitaOption
TypeRegistry sets an explicit type registry.