Documentation
¶
Overview ¶
Package dogma defines the API for Dogma, a suite of tools for building robust message-driven applications in Go.
Index ¶
- Variables
- func ExecutesCommand[T Command](...ExecutesCommandOption) interface{ ... }
- func HandlesCommand[T Command](...HandlesCommandOption) interface{ ... }
- func HandlesEvent[T Event](...HandlesEventOption) interface{ ... }
- func RecordsEvent[T Event](...RecordsEventOption) interface{ ... }
- func RegisterCommand[T interface{ ... }, E any](id string, _ ...RegisterCommandOption)
- func RegisterEvent[T interface{ ... }, E any](id string, _ ...RegisterEventOption)
- func RegisterTimeout[T interface{ ... }, E any](id string, _ ...RegisterTimeoutOption)
- func RegisteredMessageTypes() iter.Seq[RegisteredMessageType]
- func SchedulesTimeout[T Timeout](...SchedulesTimeoutOption) interface{ ... }
- type AggregateCommandScope
- type AggregateConfigurer
- type AggregateHandlerRoute
- type AggregateMessageHandler
- type AggregateRoot
- type AggregateRoute
- type Application
- type ApplicationConfigurer
- type Command
- type CommandExecutor
- type CommandValidationScope
- type ConcurrencyPreference
- type DisableOption
- type Event
- type EventValidationScope
- type ExecuteCommandOption
- type ExecutesCommandOption
- type ExecutesCommandRoute
- type HandlerConfigurer
- type HandlerRoute
- func ViaAggregate(h AggregateMessageHandler, _ ...ViaAggregateOption) HandlerRoute
- func ViaIntegration(h IntegrationMessageHandler, _ ...ViaIntegrationOption) HandlerRoute
- func ViaProcess(h ProcessMessageHandler, _ ...ViaProcessOption) HandlerRoute
- func ViaProjection(h ProjectionMessageHandler, _ ...ViaProjectionOption) HandlerRoute
- type HandlerScope
- type HandlesCommandOption
- type HandlesCommandRoute
- type HandlesEventOption
- type HandlesEventRoute
- type IdempotencyKeyOption
- type IntegrationCommandScope
- type IntegrationConfigurer
- type IntegrationHandlerRoute
- type IntegrationMessageHandler
- type IntegrationRoute
- type Message
- type MessageRoute
- type MessageValidationScope
- type NoCompactBehavior
- type NoResetBehavior
- type NoSnapshotBehavior
- type NoTimeoutMessagesBehavior
- type ProcessConfigurer
- type ProcessEventScope
- type ProcessHandlerRoute
- type ProcessMessageHandler
- type ProcessRoot
- type ProcessRoute
- type ProcessScope
- type ProcessTimeoutScope
- type ProjectionCompactScope
- type ProjectionConfigurer
- type ProjectionEventScope
- type ProjectionHandlerRoute
- type ProjectionMessageHandler
- type ProjectionResetScope
- type ProjectionRoute
- type RecordsEventOption
- type RecordsEventRoute
- type RegisterCommandOption
- type RegisterEventOption
- type RegisterTimeoutOption
- type RegisteredMessageType
- type SchedulesTimeoutOption
- type SchedulesTimeoutRoute
- type StatelessProcessBehavior
- type Timeout
- type TimeoutValidationScope
- type ViaAggregateOption
- type ViaIntegrationOption
- type ViaProcessOption
- type ViaProjectionOption
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotSupported is the error returned when a feature is not supported // by a particular implementation. // // It may be returned by: // - [AggregateRoot].MarshalBinary // - [AggregateRoot].UnmarshalBinary // - [ProjectionMessageHandler].Reset ErrNotSupported = errors.New("not supported") )
var UnexpectedMessage unexpectedMessage
UnexpectedMessage is a panic value used by a message handler when it receives a message of a type that it didn't expect.
Functions ¶
func ExecutesCommand ¶ added in v0.12.0
func ExecutesCommand[T Command](...ExecutesCommandOption) interface { ProcessRoute }
ExecutesCommand configures a ProcessMessageHandler as a producer of Command messages of type T.
It panics if T isn't in the message registry, see RegisterCommand.
Pass the returned MessageRoute to ProcessConfigurer.Routes.
The application may have multiple handlers that execute T.
func HandlesCommand ¶ added in v0.12.0
func HandlesCommand[T Command](...HandlesCommandOption) interface { AggregateRoute IntegrationRoute }
HandlesCommand configures an AggregateMessageHandler or IntegrationMessageHandler as a consumer of Command messages of type T.
It panics if T isn't in the message registry, see RegisterCommand.
Pass the returned MessageRoute to AggregateConfigurer.Routes or IntegrationConfigurer.Routes.
The engine panics if the application has multiple handlers that handle T.
func HandlesEvent ¶ added in v0.12.0
func HandlesEvent[T Event](...HandlesEventOption) interface { ProcessRoute ProjectionRoute }
HandlesEvent configures a ProcessMessageHandler or ProjectionMessageHandler as a consumer of Event messages of type T.
It panics if T isn't in the message registry, see RegisterEvent.
Pass the returned MessageRoute to ProcessConfigurer.Routes or ProjectionConfigurer.Routes.
An application may have multiple handlers that handle T.
func RecordsEvent ¶ added in v0.12.0
func RecordsEvent[T Event](...RecordsEventOption) interface { AggregateRoute IntegrationRoute }
RecordsEvent configures an AggregateMessageHandler or IntegrationMessageHandler as a producer of Event messages of type T.
It panics if T isn't in the message registry, see RegisterEvent.
Pass the returned MessageRoute to AggregateConfigurer.Routes or IntegrationConfigurer.Routes.
The engine panics if the application has multiple handlers that record T.
func RegisterCommand ¶ added in v0.16.0
func RegisterCommand[
T interface {
Command
*E
},
E any,
](id string, _ ...RegisterCommandOption)
RegisterCommand adds a Command message type to Dogma's message registry, making it eligible for use with HandlesCommand and ExecutesCommand.
id uniquely identifies the message type. The value must be a canonical RFC 9562 UUID string, such as "65f9620a-65c1-434e-8292-60cd7938c4de", and is case-insensitive. The engine uses the ID to associate message data with the correct Go type.
func RegisterEvent ¶ added in v0.16.0
func RegisterEvent[
T interface {
*E
Event
},
E any,
](id string, _ ...RegisterEventOption)
RegisterEvent adds a Event message type to Dogma's message registry, making it eligible for use with HandlesEvent and RecordsEvent.
id uniquely identifies the message type. The value must be a canonical RFC 9562 UUID string, such as "65f9620a-65c1-434e-8292-60cd7938c4de", and is case-insensitive. The engine uses the ID to associate message data with the correct Go type.
func RegisterTimeout ¶ added in v0.16.0
func RegisterTimeout[
T interface {
*E
Timeout
},
E any,
](id string, _ ...RegisterTimeoutOption)
RegisterTimeout adds a Timeout message type to the Dogma message registry, making it eligible for use with SchedulesTimeout.
id uniquely identifies the message type. The value must be a canonical RFC 9562 UUID string, such as "65f9620a-65c1-434e-8292-60cd7938c4de", and is case-insensitive. The engine uses the ID to associate message data with the correct Go type.
func RegisteredMessageTypes ¶ added in v0.16.0
func RegisteredMessageTypes() iter.Seq[RegisteredMessageType]
RegisteredMessageTypes returns an iterator that yields information about each message in the Dogma message registry.
Use RegisterCommand, RegisterEvent, or RegisterTimeout to add messages to the registry.
func SchedulesTimeout ¶ added in v0.12.0
func SchedulesTimeout[T Timeout](...SchedulesTimeoutOption) interface { ProcessRoute }
SchedulesTimeout configures a ProcessMessageHandler as a scheduler of Timeout messages of type T.
It panics if T isn't in the message registry, see RegisterTimeout.
Pass the returned MessageRoute to ProcessConfigurer.Routes.
The application may have multiple handlers that schedule T.
Types ¶
type AggregateCommandScope ¶
type AggregateCommandScope interface {
HandlerScope
// InstanceID returns the ID of the aggregate instance that the [Command]
// targets, as returned by [AggregateMessageHandler].RouteCommandToInstance.
InstanceID() string
// RecordEvent records an [Event] that results from handling the [Command].
//
// It applies the event to the aggregate root by calling
// [AggregateRoot].ApplyEvent, making the state changes visible to the
// handler immediately.
//
// The engine persists all events recorded within this scope in a single
// atomic operation after the [AggregateMessageHandler] finishes handling
// the inbound command.
RecordEvent(Event)
}
AggregateCommandScope represents the context within which an AggregateMessageHandler handles a Command message.
type AggregateConfigurer ¶
type AggregateConfigurer interface {
HandlerConfigurer
// Routes declares the message types that the handler consumes and produces.
//
// It accepts routes created by [HandlesCommand] and [RecordsEvent].
Routes(...AggregateRoute)
}
AggregateConfigurer is the interface an AggregateMessageHandler uses to declare its configuration.
The engine provides the implementation to AggregateMessageHandler.Configure during startup.
type AggregateHandlerRoute ¶ added in v0.16.0
type AggregateHandlerRoute struct {
// contains filtered or unexported fields
}
AggregateHandlerRoute is a HandlerRoute that represents a relationship between the Application and an AggregateMessageHandler.
Use ViaAggregate to construct values of this type.
func (AggregateHandlerRoute) Handler ¶ added in v0.16.0
func (r AggregateHandlerRoute) Handler() AggregateMessageHandler
Handler returns the AggregateMessageHandler for r.
type AggregateMessageHandler ¶
type AggregateMessageHandler interface {
// Configure declares the handler's configuration by calling methods on c.
//
// The configuration includes the handler's identity and message routes.
//
// The engine calls this method at least once during startup. It must
// produce the same configuration each time it's called.
Configure(c AggregateConfigurer)
// New returns a new [AggregateRoot] representing the initial state of an
// aggregate instance.
//
// The engine calls this method to get a "blank slate" when handling the
// first [Command] for a new instance or when reconstructing an existing
// instance from its historical [Event] messages.
New() AggregateRoot
// RouteCommandToInstance returns the ID of the aggregate instance that c
// targets.
//
// The return value must be a non-empty string that uniquely identifies the
// target instance. For example, in a shopping cart aggregate, the instance
// ID might be the customer's ID. RFC 9562 UUIDs are the recommended format.
//
// Commands routed to the same instance operate on the same state. There's
// no need to create an instance in advance - it "exists" once the handler
// records an [Event] against it.
//
// The engine calls this method before handling the [Command]. The
// implementation must derive the ID from information within c.
RouteCommandToInstance(c Command) string
// HandleCommand updates an aggregate instance's state by recording [Event]
// messages that represent the effects of a [Command].
//
// r is the [AggregateRoot] for the instance that the command targets, as
// determined by [AggregateMessageHandler].RouteCommandToInstance. It
// reflects the state of the targeted instance after applying its historical
// events.
//
// The implementation must not cause external side-effects or modify r
// directly. Logic must depend only on information within r, s, and c.
//
// The engine atomically persists the events recorded by exactly one
// successful invocation of this method for each command message. It doesn't
// guarantee the order, number, or concurrency of those attempts. The
// implementation doesn't need to perform any synchronization or idempotency
// checks.
HandleCommand(
r AggregateRoot,
s AggregateCommandScope,
c Command,
)
}
An AggregateMessageHandler encapsulates an application's "invariant" logic - conditions that must always hold true.
It handles Command messages and records Event messages that represent changes to application state.
An "aggregate" is a collection of related business entities that behave as a cohesive whole, such as a shopping cart and the items within it. The aggregate message handler manages the behavior and state of such aggregates. The term doesn't refer to data aggregation or summarization.
Each aggregate message handler typically manages multiple instances, where each instance represents a distinct occurrence of the aggregate. For example, a shopping cart aggregate might use one instance per customer.
Aggregates enforce business rules that must always hold true for a specific instance. For example, a shopping cart aggregate might prevent checkout if the cart is empty, or limit the number of items to 10.
type AggregateRoot ¶
type AggregateRoot interface {
// ApplyEvent updates the aggregate instance to reflect the occurrence of an
// event.
//
// The engine calls this method when loading the instance from historical
// events or recording a new event. It must handle all historical event
// types, including those no longer routed to this aggregate.
ApplyEvent(Event)
// MarshalBinary returns a binary representation of the aggregate instance's
// current state suitable for use as a snapshot.
//
// Snapshots are an optimization that reduces the number of events applied
// when loading an aggregate instance from its event history. Aggregates
// that produce few events over their instances' lifetime may omit snapshot
// support by embedding [NoSnapshotBehavior] or returning [ErrNotSupported].
MarshalBinary() ([]byte, error)
// UnmarshalBinary populates the aggregate instance's state from its binary
// representation.
//
// The implementation must clone the data if it is used after returning.
UnmarshalBinary(data []byte) error
}
An AggregateRoot is an interface for an application's working representation of an aggregate instance used within AggregateMessageHandler implementations.
It encapsulates business logic and provides a way to inspect the current state when making decisions about which events to record. The recorded events are the authoritative source of truth, not the AggregateRoot.
type AggregateRoute ¶ added in v0.12.0
type AggregateRoute interface {
MessageRoute
// contains filtered or unexported methods
}
AggregateRoute describes a message type that's routed to or from a AggregateMessageHandler.
type Application ¶
type Application interface {
// Configure declares the application's configuration by calling methods on
// c.
//
// The configuration includes the application's identity and handler routes.
//
// The engine calls this method at least once during startup. It must
// produce the same configuration each time it's called.
Configure(c ApplicationConfigurer)
}
An Application defines a collection of message handlers that work together to implement a specific business domain.
An application in the general sense must provide at least one Dogma Application implementation.
type ApplicationConfigurer ¶
type ApplicationConfigurer interface {
// Identity sets the application's unique identity.
//
// n is a short human-readable name displayed wherever the application's
// identity appears, such as in logs and telemetry signals. The value must
// be between 1 and 255 bytes in length, and contain only printable,
// non-space UTF-8 characters. Changing the handler's name doesn't affect
// its behavior.
//
// k is a key that uniquely identifies the application. The engine uses the
// key to associate application state with the correct application instance
// - it must not change. The value must be a canonical RFC 9562 UUID string,
// such as "5195fe85-eb3f-4121-84b0-be72cbc5722f", and is case-insensitive.
Identity(n, k string)
// Routes adds handler routes that associate message types with handlers.
//
// It accepts routes created by [ViaAggregate], [ViaProcess],
// [ViaIntegration], and [ViaProjection].
//
// The application doesn't declare routes for message types directly; it
// inherits routes from the handlers it contains.
Routes(...HandlerRoute)
}
ApplicationConfigurer is the interface an Application uses to declare its configuration.
The engine provides the implementation to Application.Configure during startup.
type Command ¶ added in v0.12.0
type Command interface {
Message
// Validate returns a non-nil error if the message isn't well-formed.
//
// A command is well-formed if all required information is present and
// correctly encoded such that it represents a valid action that the
// application can perform, if current state permits.
//
// The [CommandValidationScope] argument exists for forward-compatibility;
// the interface is currently empty.
Validate(CommandValidationScope) error
}
A Command is a Message that instructs an Application to perform a specific action immediately.
type CommandExecutor ¶
type CommandExecutor interface {
// ExecuteCommand submits a [Command] for execution.
//
// It returns once the engine has taken ownership of the command. It doesn't
// wait for handling to finish.
//
// The engine may invoke the command's handler more than once, but the
// command's side-effects, such as the events it produces, occur exactly
// once.
//
// If it returns a non-nil error, the engine may not have taken ownership of
// message delivery, and the application should retry execution.
//
// See [WithIdempotencyKey].
ExecuteCommand(context.Context, Command, ...ExecuteCommandOption) error
}
A CommandExecutor submits Command messages for execution.
It's the primary way that code outside of the Dogma application interacts with the engine.
type CommandValidationScope ¶ added in v0.15.0
type CommandValidationScope interface {
MessageValidationScope
// ExecutedAt returns the time at which the application submitted the
// command for execution by calling ExecuteCommand() on a [CommandExecutor]
// or [ProcessScope].
ExecutedAt() time.Time
}
CommandValidationScope provides context during Command validation.
The engine provides the implementation to Command.Validate.
This type exists for forward-compatibility.
type ConcurrencyPreference ¶ added in v0.19.0
type ConcurrencyPreference int
ConcurrencyPreference is a hint to the engine as to the best way to handle concurrent messages for a message handler.
IntegrationMessageHandler and ProjectionMessageHandler and support configuring their concurrency preference via their respective configurer interfaces.
const ( // MaximizeConcurrency is instructs the engine to process as many messages // concurrently as possible, maximizing throughput. MaximizeConcurrency ConcurrencyPreference = iota // MinimizeConcurrency is instructs the engine to attempt to process // messages one at a time, minimizing conflicts and/or contention. MinimizeConcurrency )
type DisableOption ¶ added in v0.13.1
type DisableOption interface {
// contains filtered or unexported methods
}
DisableOption is an option that modifies the behavior of the HandlerConfigurer.Disable method.
See:
- AggregateConfigurer.Disable()
- ProcessConfigurer.Disable()
- IntegrationConfigurer.Disable()
- ProjectionConfigurer.Disable()
This type exists for forward-compatibility.
type Event ¶ added in v0.12.0
type Event interface {
Message
// Validate returns a non-nil error if the message isn't well-formed.
//
// An event is well-formed if all required information is present and
// correctly encoded such that it accurately represents an action that can
// occur within the application.
//
// Validation requirements may change over time. Use the
// [EventValidationScope] to access context that may affect the strictness
// or criteria of the validation logic.
Validate(EventValidationScope) error
}
An Event is a Message that represents an action that an Application has performed.
Events capture facts about what has happened within the application and serve as a permanent record of past activity.
type EventValidationScope ¶ added in v0.15.0
type EventValidationScope interface {
MessageValidationScope
// RecordedAt returns the time at which the event occurred.
RecordedAt() time.Time
}
EventValidationScope provides context during Event validation.
The engine provides the implementation to Event.Validate.
type ExecuteCommandOption ¶ added in v0.13.0
type ExecuteCommandOption interface {
// contains filtered or unexported methods
}
ExecuteCommandOption is an option that modifies the behavior of CommandExecutor.ExecuteCommand.
func WithIdempotencyKey ¶ added in v0.16.0
func WithIdempotencyKey(key string) ExecuteCommandOption
WithIdempotencyKey returns an ExecuteCommandOption that sets a unique identifier for the Command.
Use an idempotency key when retrying a failed CommandExecutor.ExecuteCommand call to ensure that the engine doesn't execute the command multiple times.
type ExecutesCommandOption ¶ added in v0.13.0
type ExecutesCommandOption interface {
// contains filtered or unexported methods
}
ExecutesCommandOption is an option that modifies the behavior of ExecutesCommand.
This type exists for forward-compatibility.
type ExecutesCommandRoute ¶ added in v0.12.0
type ExecutesCommandRoute struct {
// contains filtered or unexported fields
}
ExecutesCommandRoute is a HandlerRoute that represents a handler's ability to execute Command messages of a specific type.
Use ExecutesCommand to construct values of this type.
func (ExecutesCommandRoute) Type ¶ added in v0.12.0
func (r ExecutesCommandRoute) Type() RegisteredMessageType
Type returns the RegisteredMessageType for r.
type HandlerConfigurer ¶ added in v0.16.0
type HandlerConfigurer interface {
// Identity sets the handler's unique identity.
//
// n is a short human-readable name displayed wherever the handler's
// identity appears, such as in logs and telemetry signals. The value must
// be between 1 and 255 bytes in length, and contain only printable,
// non-space UTF-8 characters. Changing the handler's name doesn't affect
// its behavior. Each handler within an application must have a unique name.
//
// k is a key that uniquely identifies the handler. The engine uses the key
// to associate handler state with the correct handler instance - it must
// not change. The value must be a canonical RFC 9562 UUID string, such as
// "3a6da031-aa6c-406a-8453-73762f71f917", and is case-insensitive.
Identity(n string, k string)
// Disable excludes the handler from the application's runtime without
// removing it from the application's configuration.
//
// Disabling a handler is appropriate when it cannot function in the current
// execution environment but should still be present for documentation,
// static analysis, and route discovery purposes.
//
// Prefer conditionally disabling a handler over conditionally adding it to
// the application.
Disable(...DisableOption)
}
A HandlerConfigurer is the interface a handler uses to declare its configuration. It defines configuration methods common to all handler types.
Each handler type has a corresponding configurer type that extends this interface.
See:
type HandlerRoute ¶ added in v0.16.0
type HandlerRoute interface {
// contains filtered or unexported methods
}
HandlerRoute is an interface for types that represent a relationship between the Application and a message handler.
Use ViaAggregate, ViaProcess, ViaIntegration, or ViaProjection to create a HandlerRoute.
func ViaAggregate ¶ added in v0.16.0
func ViaAggregate(h AggregateMessageHandler, _ ...ViaAggregateOption) HandlerRoute
ViaAggregate configures the Application to route messages to and from an AggregateMessageHandler.
Pass the returned HandlerRoute to ApplicationConfigurer.Routes.
func ViaIntegration ¶ added in v0.16.0
func ViaIntegration(h IntegrationMessageHandler, _ ...ViaIntegrationOption) HandlerRoute
ViaIntegration configures the Application to route messages to and from an IntegrationMessageHandler.
Pass the returned HandlerRoute to ApplicationConfigurer.Routes.
func ViaProcess ¶ added in v0.16.0
func ViaProcess(h ProcessMessageHandler, _ ...ViaProcessOption) HandlerRoute
ViaProcess configures the Application to route messages to and from a ProcessMessageHandler.
Pass the returned HandlerRoute to ApplicationConfigurer.Routes.
func ViaProjection ¶ added in v0.16.0
func ViaProjection(h ProjectionMessageHandler, _ ...ViaProjectionOption) HandlerRoute
ViaProjection configures the Application to route messages to a ProjectionMessageHandler.
Pass the returned HandlerRoute to ApplicationConfigurer.Routes.
type HandlerScope ¶ added in v0.16.0
type HandlerScope interface {
// Now returns the current local time according to the engine.
//
// Use this method in preference to [time.Now]; its return value may differ
// in certain situations, such as when executing tests or when compensating
// for clock skew in a distributed system.
Now() time.Time
// Log records an informational message using [fmt.Printf]-style formatting.
//
// The message should be clear and relevant to developers and non-technical
// stakeholders familiar with the application's domain. It's not intended
// for display to end users.
//
// Use lowercase sentences with no trailing punctuation and omit sensitive
// information.
//
// Use this method to explain conditions or decisions that aren't captured
// in a [Message]. For example, if a handler receives a command to cancel a
// shopping cart order after shipping, it might log “cannot cancel order
// #49412, it has already shipped”.
Log(format string, args ...any)
}
HandlerScope represents the context within which the engine invokes a message handler.
Each operation that a handler performs has a corresponding scope type that extends this interface:
type HandlesCommandOption ¶ added in v0.13.0
type HandlesCommandOption interface {
// contains filtered or unexported methods
}
HandlesCommandOption is an option that modifies the behavior of HandlesCommand.
This type exists for forward-compatibility.
type HandlesCommandRoute ¶ added in v0.12.0
type HandlesCommandRoute struct {
// contains filtered or unexported fields
}
HandlesCommandRoute is a HandlerRoute that represents a handler's ability to handle Command messages of a specific type.
Use HandlesCommand to construct values of this type.
func (HandlesCommandRoute) Type ¶ added in v0.12.0
func (r HandlesCommandRoute) Type() RegisteredMessageType
Type returns the RegisteredMessageType for r.
type HandlesEventOption ¶ added in v0.13.0
type HandlesEventOption interface {
// contains filtered or unexported methods
}
HandlesEventOption is an option that modifies the behavior of HandlesEvent.
This type exists for forward-compatibility.
type HandlesEventRoute ¶ added in v0.12.0
type HandlesEventRoute struct {
// contains filtered or unexported fields
}
HandlesEventRoute is a HandlerRoute that represents a handler's ability to handle Event messages of a specific type.
Use HandlesEvent to construct values of this type.
func (HandlesEventRoute) Type ¶ added in v0.12.0
func (r HandlesEventRoute) Type() RegisteredMessageType
Type returns the RegisteredMessageType for r.
type IdempotencyKeyOption ¶ added in v0.16.0
type IdempotencyKeyOption struct {
// contains filtered or unexported fields
}
IdempotencyKeyOption is an ExecuteCommandOption that sets a unique identifier for a Command.
Use WithIdempotencyKey to create values of this type.
func (IdempotencyKeyOption) Key ¶ added in v0.16.0
func (o IdempotencyKeyOption) Key() string
Key returns the idempotency key.
type IntegrationCommandScope ¶
type IntegrationCommandScope interface {
HandlerScope
// RecordEvent records an [Event] that results from handling the [Command].
//
// The engine persists all events recorded within this scope in a single
// atomic operation after the [IntegrationMessageHandler] finishes handling
// the inbound command. If the handler returns a non-nil error, the engine
// discards the events.
RecordEvent(Event)
}
IntegrationCommandScope represents the context within which an IntegrationMessageHandler handles a Command message.
type IntegrationConfigurer ¶
type IntegrationConfigurer interface {
HandlerConfigurer
// Routes declares the message types that the handler consumes and produces.
//
// It accepts routes created by [HandlesCommand] and [RecordsEvent].
Routes(...IntegrationRoute)
// ConcurrencyPreference provides a hint to the engine as to the best way to
// handle concurrent messages for this handler.
//
// The default is [MaximizeConcurrency].
ConcurrencyPreference(ConcurrencyPreference)
}
IntegrationConfigurer is the interface an IntegrationMessageHandler uses to declare its configuration.
The engine provides the implementation to IntegrationMessageHandler.Configure during startup.
type IntegrationHandlerRoute ¶ added in v0.16.0
type IntegrationHandlerRoute struct {
// contains filtered or unexported fields
}
IntegrationHandlerRoute is a HandlerRoute that represents a relationship between the Application and an IntegrationMessageHandler.
Use ViaIntegration to construct values of this type.
func (IntegrationHandlerRoute) Handler ¶ added in v0.16.0
func (r IntegrationHandlerRoute) Handler() IntegrationMessageHandler
Handler returns the IntegrationMessageHandler for r.
type IntegrationMessageHandler ¶
type IntegrationMessageHandler interface {
// Configure declares the handler's configuration by calling methods on c.
//
// The configuration includes the handler's identity and message routes.
//
// The engine calls this method at least once during startup. It must
// produce the same configuration each time it's called.
Configure(c IntegrationConfigurer)
// HandleCommand handles a [Command] message by performing an action outside
// the Dogma application.
//
// It may cause side-effects in external systems, such as invoking a
// third-party API. It may use s to record one or more [Event] messages that
// describe the outcome.
//
// The engine atomically persists the events recorded by exactly one
// successful invocation of this method for each command message. It doesn't
// guarantee the order, number, or concurrency of those attempts. The
// implementation must ensure that the command's external side-effects are
// idempotent and safe for concurrent execution.
HandleCommand(
ctx context.Context,
s IntegrationCommandScope,
c Command,
) error
}
An IntegrationMessageHandler connects a Dogma application to an external system.
It handles Command messages, and may record Event messages to describe the outcome.
Integration message handlers encapsulate integration logic such as sending an email, charging a credit card, or updating a third-party API. They should implement only the "glue code". For example, an integration with a payment gateway might debit a customer's credit card, but shouldn't apply discounts or calculate sales tax.
type IntegrationRoute ¶ added in v0.12.0
type IntegrationRoute interface {
MessageRoute
// contains filtered or unexported methods
}
IntegrationRoute is an interface for types that represent a relationship between an IntegrationMessageHandler and a message type.
Use HandlesCommand or RecordsEvent to create an IntegrationRoute.
type Message ¶
type Message interface {
// MessageDescription returns a concise human-readable explanation of the
// message's meaning for use in contexts such as logging and telemetry.
//
// The description should be clear and relevant to developers and
// non-technical stakeholders familiar with the application's domain. It's
// not intended for display to end users.
//
// Use lowercase sentences with no trailing punctuation. Omit sensitive
// information and overly specific details that don't alter the message's
// intent.
//
// Descriptions of [Command] messages should use present-continuous tense.
// For example: "adding 10 widgets to Alex's shopping cart".
//
// Descriptions of [Event] messages should use past tense. For example:
// "added 10 widgets to Alex's shopping cart".
//
// Descriptions of [Timeout] messages should read as though the timeout has
// just elapsed. For example: "Alex's cart is now inactive" or "24 hours
// elapsed since first item added to Alex's cart".
//
// Be wary of assuming a specific actor if the message doesn't explicitly
// encode that information. For example, prefer "Alex's purchase completed"
// over "Alex completed their purchase". This guidance is especially
// relevant to [Event] messages, where each type should represent a specific
// state change regardless of who initiated it.
MessageDescription() string
// MarshalBinary returns the message's binary representation, suitable for
// persistence or transmission over the network.
MarshalBinary() ([]byte, error)
// UnmarshalBinary populates the message from its binary representation.
//
// The implementation must clone the data if it is used after returning.
UnmarshalBinary([]byte) error
}
A Message describes something an Application can do or has done.
Each message type implements either Command, Event, or Timeout.
type MessageRoute ¶ added in v0.16.0
type MessageRoute interface {
Type() RegisteredMessageType
// contains filtered or unexported methods
}
MessageRoute is an interface for types that describe a relationship between a message handler and a specific message type.
type MessageValidationScope ¶ added in v0.16.0
type MessageValidationScope interface {
// IsNew returns true when a handler or [CommandExecutor] is creating a new
// message, or false when the engine is re-validating a message that it has
// already accepted.
//
// Use the distinction to apply different validation rules for new messages
// versus existing messages while keeping all validation logic in one
// location.
IsNew() bool
}
MessageValidationScope provides context during Message validation.
Each message type has a corresponding scope type that extends this interface:
type NoCompactBehavior ¶ added in v0.10.0
type NoCompactBehavior struct{}
NoCompactBehavior is an embeddable type for ProjectionMessageHandler implementations that don't require compaction.
Embed this type in a ProjectionMessageHandler when projection data doesn't grow unbounded or when an external system handles compaction.
func (NoCompactBehavior) Compact ¶ added in v0.10.0
func (NoCompactBehavior) Compact(context.Context, ProjectionCompactScope) error
Compact returns nil without performing any operations.
type NoResetBehavior ¶ added in v0.18.0
type NoResetBehavior struct{}
NoResetBehavior is an embeddable type for ProjectionMessageHandler implementations that don't support resetting their state.
Embed this type in a ProjectionMessageHandler when resetting projection data isn't feasible or required.
func (NoResetBehavior) Reset ¶ added in v0.18.0
func (NoResetBehavior) Reset(context.Context, ProjectionResetScope) error
Reset returns an error indicating that reset is not supported.
type NoSnapshotBehavior ¶ added in v0.17.0
type NoSnapshotBehavior struct{}
NoSnapshotBehavior is an embeddable type for AggregateRoot implementations that don't support binary snapshots.
func (NoSnapshotBehavior) MarshalBinary ¶ added in v0.17.0
func (NoSnapshotBehavior) MarshalBinary() ([]byte, error)
MarshalBinary always returns ErrNotSupported.
func (NoSnapshotBehavior) UnmarshalBinary ¶ added in v0.17.0
func (NoSnapshotBehavior) UnmarshalBinary([]byte) error
UnmarshalBinary always returns ErrNotSupported.
type NoTimeoutMessagesBehavior ¶ added in v0.5.0
type NoTimeoutMessagesBehavior struct{}
NoTimeoutMessagesBehavior is an embeddable type for ProcessMessageHandler implementations that don't use Timeout messages.
Embed this type in a ProcessMessageHandler to signal that the handler doesn't schedule timeouts and to avoid boilerplate code that's never used.
func (NoTimeoutMessagesBehavior) HandleTimeout ¶ added in v0.5.0
func (NoTimeoutMessagesBehavior) HandleTimeout( context.Context, ProcessRoot, ProcessTimeoutScope, Timeout, ) error
HandleTimeout panics with the UnexpectedMessage value.
type ProcessConfigurer ¶
type ProcessConfigurer interface {
HandlerConfigurer
// Routes declares the message types that the handler consumes and produces.
//
// It accepts routes created by [HandlesEvent], [ExecutesCommand], and
// [SchedulesTimeout].
Routes(...ProcessRoute)
}
ProcessConfigurer is the interface that a ProcessMessageHandler uses to declare its configuration.
The engine provides the implementation to ProcessMessageHandler.Configure during startup.
type ProcessEventScope ¶
type ProcessEventScope interface {
ProcessScope
// RecordedAt returns the time at which the inbound [Event] occurred.
RecordedAt() time.Time
}
ProcessEventScope represents the context within which a ProcessMessageHandler handles an Event message.
type ProcessHandlerRoute ¶ added in v0.16.0
type ProcessHandlerRoute struct {
// contains filtered or unexported fields
}
ProcessHandlerRoute is a HandlerRoute that represents a relationship between the Application and a ProcessMessageHandler.
See ViaProcess to construct values of this type.
func (ProcessHandlerRoute) Handler ¶ added in v0.16.0
func (r ProcessHandlerRoute) Handler() ProcessMessageHandler
Handler returns the ProcessMessageHandler for r.
type ProcessMessageHandler ¶
type ProcessMessageHandler interface {
// Configure declares the handler's configuration by calling methods on c.
//
// The configuration includes the handler's identity and message routes.
//
// The engine calls this method at least once during startup. It must
// produce the same configuration each time it's called.
Configure(c ProcessConfigurer)
// New returns a new [ProcessRoot] representing the initial state of a
// process instance.
//
// The engine calls this method to get a "blank slate" when handling the
// first [Event] for a new instance. Unlike aggregates, the engine doesn't
// reconstruct process state from historical events.
//
// Not all processes maintain state. Embed [StatelessProcessBehavior] in the
// handler implementation to indicate that the process is stateless.
New() ProcessRoot
// RouteEventToInstance returns the ID of the process instance that e
// targets.
//
// If ok is false, the handler ignores the event. Otherwise, the returned ID
// must be a non-empty string that uniquely identifies the target instance.
// For example, in a shopping cart checkout process, the instance ID might
// be the customer's ID. RFC 9562 UUIDs are the recommended format.
//
// Events routed to the same instance operate on the same state. There's no
// need to create an instance in advance - it "exists" once the handler
// modifies its [ProcessRoot], executes a [Command], or schedules a
// [Timeout] against it.
//
// The engine calls this method before handling the [Event]. The
// implementation may query external data - such as the application's
// projections - but this isn't recommended. Wherever possible, it should
// derive the ID from information within e.
//
// If the process instance identified by the returned ID has ended, the
// engine ignores the event.
RouteEventToInstance(
ctx context.Context,
e Event,
) (id string, ok bool, err error)
// HandleEvent begins or advances a process in response to an [Event]
// message.
//
// r is the [ProcessRoot] for the instance that the event targets, as
// determined by [ProcessMessageHandler].RouteEventToInstance. It reflects
// the state of the targeted instance after handling any prior [Event] or
// [Timeout] messages.
//
// The implementation may update r directly, execute [Command] messages,
// schedule [Timeout] messages, or end the process. It may query external
// data - such as the application's projections - but this isn't
// recommended. Wherever possible, logic should depend solely on information
// within r, s, and e.
//
// The engine atomically persists the state changes, events, and timeouts
// produced by exactly one successful invocation of this method for each
// event message. It doesn't guarantee the order, number, or concurrency of
// those attempts. Generally, the implementation doesn't need to perform any
// synchronization or idempotency checks.
//
// The engine delivers all [Event] messages recorded within a single scope
// in the order they occurred. It also preserves the order of events from a
// single aggregate instance, even across scopes. It doesn't guarantee the
// relative delivery order of events from different handlers or aggregate
// instances.
HandleEvent(
ctx context.Context,
r ProcessRoot,
s ProcessEventScope,
e Event,
) error
// HandleTimeout advances a process in response to a [Timeout] message.
//
// r is the [ProcessRoot] for the instance that scheduled the timeout. It
// reflects the state of the targeted instance after handling any prior
// [Event] or [Timeout] messages.
//
// The implementation may update r directly, execute [Command] messages,
// schedule [Timeout] messages, or end the process. It may query external
// data - such as the application's projections - but this isn't
// recommended. Wherever possible, logic should depend solely on information
// within r, s, and t.
//
// The engine atomically persists the state changes, events, and timeouts
// produced by exactly one successful invocation of this method for each
// timeout message. It doesn't guarantee the order, number, or concurrency
// of those attempts. Generally, the implementation doesn't need to perform
// any synchronization or idempotency checks.
//
// The engine attempts to deliver timeout messages at their scheduled time.
// It may deliver them later when recovering from downtime or retrying after
// a failure. It doesn't guarantee the relative delivery order of timeout
// messages with the same scheduled time.
//
// Not all processes use timeouts. Embed [NoTimeoutMessagesBehavior] in the
// handler implementation to indicate that timeout messages aren't used.
HandleTimeout(
ctx context.Context,
r ProcessRoot,
s ProcessTimeoutScope,
t Timeout,
) error
}
A ProcessMessageHandler encapsulates an application's "workflow" logic - stateful decision-making that spans multiple Command messages.
It handles Event messages and executes Command to enact further application state changes. It may also schedule Timeout messages to perform actions at specific times. For example, to send a reminder if a customer hasn't completed the checkout process within one hour.
Each process message handler typically manages multiple instances, where each instance represents a distinct occurrence of the process. For example, a shopping cart checkout process might use one instance per customer.
Process message handlers coordinate state changes that involve some combination of multiple aggregate instances, integrations with external systems, and time-based logic. As a general rule, they should implement only workflow logic. For example, a process might decide when to refund a customer's purchase, but shouldn't calculate the refund amount or interact directly with the payment processor.
type ProcessRoot ¶
type ProcessRoot interface {
// MarshalBinary returns a binary representation of the process instsance's
// current state.
MarshalBinary() ([]byte, error)
// UnmarshalBinary populates the process instance's state from its binary
// representation.
//
// The implementation must clone the data if it is used after returning.
UnmarshalBinary(data []byte) error
}
A ProcessRoot is an interface for an application's representation of a process instance used within ProcessMessageHandler implementations.
It encapsulates process logic and provides a way to inspect the current state when making decisions about which commands to execute and which timeouts to schedule.
var StatelessProcessRoot ProcessRoot = statelessProcessRoot{}
StatelessProcessRoot is an empty ProcessRoot for processes that don't maintain any state.
Embed StatelessProcessBehavior in a ProcessMessageHandler to use this type as its ProcessRoot implementation.
The engine may provide optimized persistence for stateless processes that use this type.
type ProcessRoute ¶ added in v0.12.0
type ProcessRoute interface {
MessageRoute
// contains filtered or unexported methods
}
ProcessRoute describes a message type that's routed to or from a ProcessMessageHandler.
type ProcessScope ¶ added in v0.16.0
type ProcessScope interface {
HandlerScope
// InstanceID returns the ID of the process instance that the message
// targets.
//
// When handling an [Event] message, it returns the ID produced by
// [ProcessMessageHandler].RouteEventToInstance during routing.
//
// When handling a [Timeout] message, it returns the ID of the instance that
// scheduled the timeout.
InstanceID() string
// End signals the end of a process.
//
// The engine discards the instance's state, cancels any pending [Timeout]
// messages. It ignores any future messages that target the ended instance.
End()
// ExecuteCommand submits a [Command] for execution.
//
// The engine persists all commands and timeouts produced within this scope
// in a single atomic operation after the [ProcessMessageHandler] finishes
// handling the inbound message. If the handler returns a non-nil error, the
// engine discards the messages.
//
// This method panics if the process instance has ended.
ExecuteCommand(Command)
// ScheduleTimeout schedules a [Timeout] message to occur at the specified
// time.
//
// The engine persists all commands and timeouts produced within this scope
// in a single atomic operation after the [ProcessMessageHandler] finishes
// handling the inbound message. If the handler returns a non-nil error, the
// engine discards the messages.
//
// This method panics if the process instance has ended.
ScheduleTimeout(Timeout, time.Time)
}
ProcessScope represents the context within which a ProcessMessageHandler handles a message.
Each kind of message handled by a process message handler has a corresponding scope type that extends this interface:
type ProcessTimeoutScope ¶
type ProcessTimeoutScope interface {
ProcessScope
// ScheduledFor returns the time at which the timeout occurred.
//
// Even though the engine attempts to deliver timeouts at their scheduled
// time, it may deliver them later when recovering from downtime or retrying
// after a failure.
ScheduledFor() time.Time
}
ProcessTimeoutScope represents the context within which a ProcessMessageHandler handles a Timeout message.
type ProjectionCompactScope ¶ added in v0.10.0
type ProjectionCompactScope interface {
HandlerScope
}
ProjectionCompactScope represents the context within which a ProjectionMessageHandler compacts its data.
type ProjectionConfigurer ¶
type ProjectionConfigurer interface {
HandlerConfigurer
// Routes declares the message types that the handler consumes.
//
// It accepts routes created by [HandlesEvent].
Routes(...ProjectionRoute)
// ConcurrencyPreference provides a hint to the engine as to the best way to
// handle concurrent messages for this handler.
//
// The default is [MaximizeConcurrency].
ConcurrencyPreference(ConcurrencyPreference)
}
ProjectionConfigurer is the interface that a ProjectionMessageHandler uses to declare its configuration.
The engine provides the implementation to ProjectionMessageHandler.Configure during startup.
type ProjectionEventScope ¶
type ProjectionEventScope interface {
HandlerScope
// RecordedAt returns the time at which the [Event] occurred.
RecordedAt() time.Time
// StreamID returns the RFC 9562 UUID that identifies the event stream to
// which the [Event] belongs.
StreamID() string
// Offset returns the event's zero-based offset within the stream.
Offset() uint64
// CheckpointOffset returns the offset from which the handler should resume
// handling events from this stream, according to the engine.
//
// It may be lower than the incoming event's offset when the stream contains
// event types that the handler doesn't consume.
CheckpointOffset() uint64
}
ProjectionEventScope represents the context within which a ProjectionMessageHandler handles an Event message.
type ProjectionHandlerRoute ¶ added in v0.16.0
type ProjectionHandlerRoute struct {
// contains filtered or unexported fields
}
ProjectionHandlerRoute is a HandlerRoute that represents a relationship between the Application and a ProjectionMessageHandler.
Use ViaProjection to construct values of this type.
func (ProjectionHandlerRoute) Handler ¶ added in v0.16.0
func (r ProjectionHandlerRoute) Handler() ProjectionMessageHandler
Handler returns the ProjectionMessageHandler for r.
type ProjectionMessageHandler ¶
type ProjectionMessageHandler interface {
// Configure declares the handler's configuration by calling methods on c.
//
// The configuration includes the handler's identity and message routes.
//
// The engine calls this method at least once during startup. It must
// produce the same configuration each time it's called.
Configure(c ProjectionConfigurer)
// HandleEvent updates the projection to reflect the occurrence of an
// [Event].
//
// The [ProjectionEventScope] s exposes the ID of the event stream to which
// the incoming event belongs, the event's offset within that stream, and
// the checkpoint offset at which the engine expects the handler to resume
// consuming from the stream.
//
// If the engine and handler agree on the checkpoint offset, the handler
// must atomically apply the event and update its checkpoint offset to one
// greater than the incoming event's offset. Otherwise, the handler must not
// modify any data.
//
// In either case, the method returns cp, the new checkpoint offset for this
// stream. If cp is one greater than the offset of the incoming event, the
// engine considers the event handled successfully. Otherwise, an OCC
// conflict has occurred, and the engine resumes delivering events starting
// at cp.
//
// A non-nil error indicates that the handler encountered a runtime problem
// other than an OCC conflict.
//
// The engine arranges events on streams such that it delivers all events
// within a single scope in the order they occurred. It also preserves the
// order of events from a single aggregate instance, even across scopes. It
// doesn't guarantee the relative delivery order of events from different
// handlers or aggregate instances.
//
// See:
// - [ProjectionEventScope].StreamID
// - [ProjectionEventScope].Offset
// - [ProjectionEventScope].CheckpointOffset
HandleEvent(
ctx context.Context,
s ProjectionEventScope,
e Event,
) (cp uint64, err error)
// CheckpointOffset returns the offset at which the handler expects to
// resume handling events from a specific stream.
//
// id is an RFC 9562 UUID that identifies the event stream, such as
// "c50b5804-8312-4c61-b32c-9fbf49688db3". UUIDs are case-insensitive, but
// the engine must use a lowercase representation.
CheckpointOffset(ctx context.Context, id string) (uint64, error)
// Compact reduces the projection's size by removing or consolidating data.
//
// The handler might delete obsolete entries, merge fine-grained data into
// summaries, or move old data to archival storage. The specific strategy
// depends on the projection's purpose and access patterns.
//
// The implementation should perform compaction incrementally to make some
// progress even if ctx reaches its deadline.
//
// The engine may call this method at any time, including in parallel with
// handling an event.
//
// Not all projections need compaction. Embed [NoCompactBehavior] in the
// handler to indicate compaction not required.
Compact(ctx context.Context, s ProjectionCompactScope) error
// Reset clears all projection data and checkpoint offsets such that the
// projection data is rebuilt by handling all historical events.
//
// Not all projections can be reset. Embed [NoResetBehavior] in the handler
// to indicate that reset is not supported.
Reset(ctx context.Context, s ProjectionResetScope) error
}
A ProjectionMessageHandler builds a denormalized view of the application's state that's optimized for querying.
It handles Event messages to build and update projections - partial representations of application state tailored to specific use cases. For example, a projection might contain a list of customers with active shopping carts.
Each event belongs to an ordered event stream, identified by a UUID. The engine delivers events in the order they appear on the stream, using a numeric offset to represent each event's position.
A single projection may receive events from multiple streams, which may belong to different applications.
To ensure exactly-once event processing, the handler must implement optimistic concurrency control (OCC) based on each event's position within an event stream. The github.com/dogmatiq/projectionkit module provides adapters for popular databases, like PostgreSQL and DynamoDB, that handle the OCC details.
type ProjectionResetScope ¶ added in v0.18.0
type ProjectionResetScope interface {
HandlerScope
}
ProjectionResetScope represents the context within which a ProjectionMessageHandler resets its data.
type ProjectionRoute ¶ added in v0.12.0
type ProjectionRoute interface {
MessageRoute
// contains filtered or unexported methods
}
ProjectionRoute describes a message type that's routed to a ProjectionMessageHandler.
type RecordsEventOption ¶ added in v0.13.0
type RecordsEventOption interface {
// contains filtered or unexported methods
}
RecordsEventOption is an option that modifies the behavior of RecordsEvent.
This type exists for forward-compatibility.
type RecordsEventRoute ¶ added in v0.12.0
type RecordsEventRoute struct {
// contains filtered or unexported fields
}
RecordsEventRoute is a HandlerRoute that represents a handler's ability to record Event messages of a specific type.
Use RecordsEvent to construct values of this type.
func (RecordsEventRoute) Type ¶ added in v0.12.0
func (r RecordsEventRoute) Type() RegisteredMessageType
Type returns the RegisteredMessageType for r.
type RegisterCommandOption ¶ added in v0.16.0
type RegisterCommandOption interface {
// contains filtered or unexported methods
}
RegisterCommandOption is an option that modifies the behavior of RegisterCommand.
This type exists for forward-compatibility.
type RegisterEventOption ¶ added in v0.16.0
type RegisterEventOption interface {
// contains filtered or unexported methods
}
RegisterEventOption is an option that modifies the behavior of RegisterEvent.
This type exists for forward-compatibility.
type RegisterTimeoutOption ¶ added in v0.16.0
type RegisterTimeoutOption interface {
// contains filtered or unexported methods
}
RegisterTimeoutOption is an option that modifies the behavior of RegisterTimeout.
This type exists for forward-compatibility.
type RegisteredMessageType ¶ added in v0.16.0
type RegisteredMessageType struct {
// contains filtered or unexported fields
}
RegisteredMessageType contains information about an implementation of Command, Event, or Timeout that's in Dogma's message registry.
Use RegisterCommand, RegisterEvent, or RegisterTimeout to add messages to the registry.
func RegisteredMessageTypeByID ¶ added in v0.16.0
func RegisteredMessageTypeByID(id string) (t RegisteredMessageType, ok bool)
RegisteredMessageTypeByID returns the RegisteredMessageType with the given ID.
The ID is a canonical RFC 9562 UUID string, such as "65f9620a-65c1-434e-8292-60cd7938c4de", and is case-insensitive.
ok is false if there is no such message type in the registry.
func RegisteredMessageTypeFor ¶ added in v0.16.0
func RegisteredMessageTypeFor[T Message]() (t RegisteredMessageType, ok bool)
RegisteredMessageTypeFor returns the RegisteredMessageType for T.
ok is false if T isn't in the message type registry.
func RegisteredMessageTypeOf ¶ added in v0.17.1
func RegisteredMessageTypeOf(m Message) (t RegisteredMessageType, ok bool)
RegisteredMessageTypeOf returns the RegisteredMessageType for the given message instance.
ok is false if the message's type isn't in the message type registry.
func (RegisteredMessageType) GoType ¶ added in v0.16.0
func (t RegisteredMessageType) GoType() reflect.Type
GoType returns the reflect.Type of the message type.
func (RegisteredMessageType) ID ¶ added in v0.16.0
func (t RegisteredMessageType) ID() string
ID returns an RFC 9562 UUID that uniquely identifies the message type. The engine uses the ID to associate message data with the correct Go type.
func (RegisteredMessageType) New ¶ added in v0.16.0
func (t RegisteredMessageType) New() Message
New returns a new instance of the message type.
If the message type uses pointer receivers, it returns a non-nil pointer to a new zero-value of the underlying type.
type SchedulesTimeoutOption ¶ added in v0.13.0
type SchedulesTimeoutOption interface {
// contains filtered or unexported methods
}
SchedulesTimeoutOption is an option that modifies the behavior of SchedulesTimeout.
This type exists for forward-compatibility.
type SchedulesTimeoutRoute ¶ added in v0.12.0
type SchedulesTimeoutRoute struct {
// contains filtered or unexported fields
}
SchedulesTimeoutRoute is a HandlerRoute that represents a handler's ability to schedule Timeout messages of a specific type.
Use SchedulesTimeout to construct values of this type.
func (SchedulesTimeoutRoute) Type ¶ added in v0.12.0
func (r SchedulesTimeoutRoute) Type() RegisteredMessageType
Type returns the RegisteredMessageType for r.
type StatelessProcessBehavior ¶
type StatelessProcessBehavior struct{}
StatelessProcessBehavior is an embeddable type for ProcessMessageHandler implementations that don't maintain any state.
Embed this type in a ProcessMessageHandler to signal that the handler is stateless and to avoid boilerplate code that's never used.
func (StatelessProcessBehavior) New ¶
func (StatelessProcessBehavior) New() ProcessRoot
New returns StatelessProcessRoot.
type Timeout ¶ added in v0.12.0
type Timeout interface {
Message
// Validate returns a non-nil error if the message isn't well-formed.
//
// A timeout is well-formed if all required information is present and
// correctly encoded such that it accurately represents an action that can
// occur within the process, if current state permits.
//
// Validation requirements may change over time. Use the
// [TimeoutValidationScope] to access context that may affect the strictness
// or criteria of the validation logic.
Validate(TimeoutValidationScope) error
}
A Timeout is a Message that notifies an Application, specifically a ProcessMessageHandler that some domain-relevant period of time has elapsed.
type TimeoutValidationScope ¶ added in v0.15.0
type TimeoutValidationScope interface {
MessageValidationScope
// ScheduledAt returns the time at which the handler scheduled the timeout.
ScheduledAt() time.Time
// ScheduledFor returns the time at which the timeout occurs.
ScheduledFor() time.Time
}
TimeoutValidationScope provides context during Timeout validation.
The engine provides the implementation to Timeout.Validate.
type ViaAggregateOption ¶ added in v0.16.0
type ViaAggregateOption interface {
// contains filtered or unexported methods
}
ViaAggregateOption is an option that modifies the behavior of ViaAggregate.
This type exists for forward compatibility.
type ViaIntegrationOption ¶ added in v0.16.0
type ViaIntegrationOption interface {
// contains filtered or unexported methods
}
ViaIntegrationOption is an option that modifies the behavior of ViaIntegration.
This type exists for forward compatibility.
type ViaProcessOption ¶ added in v0.16.0
type ViaProcessOption interface {
// contains filtered or unexported methods
}
ViaProcessOption is an option that modifies the behavior of ViaProcess.
This type exists for forward compatibility.
type ViaProjectionOption ¶ added in v0.16.0
type ViaProjectionOption interface {
// contains filtered or unexported methods
}
ViaProjectionOption is an option that modifies the behavior of ViaProjection.
This type exists for forward compatibility.
Source Files
¶
- aggregate.go
- aggregate_nocoverage.go
- application.go
- concurrency.go
- doc.go
- error.go
- executor.go
- executor_nocoverage.go
- handler.go
- handlerroute.go
- handlerroute_nocoverage.go
- integration.go
- integration_nocoverage.go
- message.go
- messageroute.go
- messageroute_nocoverage.go
- messagetyperegistry.go
- process.go
- process_nocoverage.go
- projection.go
- projection_nocoverage.go
- util.go
- uuid.go