cqrs

package module
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aggregate

type Aggregate interface {
	AggregateID() uuid.UUID
	AggregateType() AggregateType
	OriginalVersion() int
	CurrentVersion() int
	Changes() []Event
	TrackChange(...Event)
	FlushChanges()
	ApplyEvent(Event) error
}

Aggregate is the aggregate of an event stream.

type AggregateConfig

type AggregateConfig interface {
	Register(AggregateType, AggregateFactory)
	New(AggregateType, uuid.UUID) (Aggregate, error)
	Factories() map[AggregateType]AggregateFactory
}

AggregateConfig ...

type AggregateFactory

type AggregateFactory func(uuid.UUID) Aggregate

AggregateFactory ...

type AggregateRepository

type AggregateRepository interface {
	Save(ctx context.Context, aggregate Aggregate) error
	Fetch(ctx context.Context, typ AggregateType, id uuid.UUID, version int) (Aggregate, error)
	FetchWithBase(ctx context.Context, aggregate Aggregate, version int) (Aggregate, error)
	FetchLatest(ctx context.Context, typ AggregateType, id uuid.UUID) (Aggregate, error)
	FetchLatestWithBase(ctx context.Context, aggregate Aggregate) (Aggregate, error)
	Remove(ctx context.Context, aggregate Aggregate) error
}

AggregateRepository ...

type AggregateType

type AggregateType string

AggregateType is the type of an aggregate.

func (AggregateType) String added in v0.11.0

func (t AggregateType) String() string

type Command

type Command interface {
	CommandType() CommandType
	AggregateType() AggregateType
	AggregateID() uuid.UUID
}

Command is a command.

type CommandBus

type CommandBus interface {
	Dispatch(context.Context, Command) error
}

CommandBus is the command bus.

type CommandConfig

type CommandConfig interface {
	Register(CommandType, CommandHandler)
	Handler(CommandType) (CommandHandler, error)
	Handlers() map[CommandType]CommandHandler
}

CommandConfig ...

type CommandHandler

type CommandHandler interface {
	HandleCommand(context.Context, Command) error
}

CommandHandler handles commands.

type CommandType

type CommandType string

CommandType is a command type.

type Container added in v0.5.0

type Container interface {
	AggregateConfig() AggregateConfig
	SetAggregateConfig(AggregateConfig)
	EventConfig() EventConfig
	SetEventConfig(EventConfig)
	CommandConfig() CommandConfig
	SetCommandConfig(CommandConfig)
	EventBus() EventBus
	EventPublisher() EventPublisher
	EventSubscriber() EventSubscriber
	SetEventBus(EventBus)
	EventStore() EventStore
	SetEventStore(EventStore)
	CommandBus() CommandBus
	SetCommandBus(CommandBus)
	Snapshots() SnapshotRepository
	SetSnapshots(SnapshotRepository)
	Aggregates() AggregateRepository
	SetAggregates(AggregateRepository)
}

Container ...

func NewContainer added in v0.11.0

func NewContainer(aggregates AggregateConfig, events EventConfig, commands CommandConfig) Container

NewContainer ...

type Event

type Event interface {
	Type() EventType
	Data() EventData
	Time() time.Time

	AggregateType() AggregateType
	AggregateID() uuid.UUID
	Version() int
}

Event is an event.

type EventBus

type EventBus interface {
	EventPublisher
	EventSubscriber
}

EventBus is the event bus.

type EventConfig

type EventConfig interface {
	Register(EventType, EventData)
	// NewData creates an EventData instance for EventType.
	// The returned object has to be a non-pointer struct.
	NewData(EventType) (EventData, error)
	Protos() map[EventType]EventData
}

EventConfig is the configuration for the events.

type EventData

type EventData interface{}

EventData is the payload of an event.

type EventMatcher added in v0.11.0

type EventMatcher func(Event) bool

EventMatcher ...

type EventPublisher

type EventPublisher interface {
	Publish(ctx context.Context, events ...Event) error
}

EventPublisher publishes events.

type EventStore

type EventStore interface {
	Save(ctx context.Context, originalVersion int, events ...Event) error
	Find(ctx context.Context, aggregateType AggregateType, aggregateID uuid.UUID, version int) (Event, error)
	Fetch(ctx context.Context, aggregateType AggregateType, aggregateID uuid.UUID, from int, to int) ([]Event, error)
	FetchAll(ctx context.Context, aggregateType AggregateType, aggregateID uuid.UUID) ([]Event, error)
	FetchFrom(ctx context.Context, aggregateType AggregateType, aggregateID uuid.UUID, from int) ([]Event, error)
	FetchTo(ctx context.Context, aggregateType AggregateType, aggregateID uuid.UUID, to int) ([]Event, error)
	RemoveAll(ctx context.Context, aggregateType AggregateType, aggregateID uuid.UUID) error
}

EventStore stores events in a database.

type EventSubscriber

type EventSubscriber interface {
	Subscribe(ctx context.Context, types ...EventType) (<-chan Event, error)
}

EventSubscriber subscribes to events.

type EventType

type EventType string

EventType is the type of an event.

func (EventType) String

func (t EventType) String() string

type SnapshotRepository

type SnapshotRepository interface {
	Save(ctx context.Context, snap Aggregate) error
	Find(ctx context.Context, typ AggregateType, id uuid.UUID, version int) (Aggregate, error)
	Latest(ctx context.Context, typ AggregateType, id uuid.UUID) (Aggregate, error)
	MaxVersion(ctx context.Context, typ AggregateType, id uuid.UUID, maxVersion int) (Aggregate, error)
	Remove(ctx context.Context, typ AggregateType, id uuid.UUID, version int) error
	RemoveAll(ctx context.Context, typ AggregateType, id uuid.UUID) error
}

SnapshotRepository ...

Directories

Path Synopsis
eventstore
Package mock_cqrs is a generated GoMock package.
Package mock_cqrs is a generated GoMock package.
aggregate
Package mock_aggregate is a generated GoMock package.
Package mock_aggregate is a generated GoMock package.
snapshot

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL