dispatcher

package
v0.23.2 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 13 Imported by: 12

Documentation

Index

Constants

View Source
const (
	TextCodeDispatchExecutorNotConfigured = "DISPATCH_EXECUTOR_NOT_CONFIGURED"
	TextCodeDispatchModeResolverFailed    = "DISPATCH_MODE_RESOLVER_FAILED"
)
View Source
const (
	TextCodeInvalidRoutingMode    = "INVALID_ROUTING_MODE"
	TextCodeDispatchRoutingLocked = "DISPATCH_ROUTING_MODE_LOCKED"
)

Variables

View Source
var ExitOnErr = false

Functions

func ClearModeResolver added in v0.17.0

func ClearModeResolver()

func CommandRunObservers added in v0.22.0

func CommandRunObservers() []command.CommandRunObserver

CommandRunObservers returns a snapshot of currently registered observers.

func CommandSubscriptionHook added in v0.23.0

func CommandSubscriptionHook[T any](runtime *Runtime) func(any, ...runner.Option) (Subscription, error)

CommandSubscriptionHook adapts RuntimeContainer's untyped composition hook to a typed runtime subscription.

func Dispatch

func Dispatch[T any](ctx context.Context, msg T) error

Dispatch executes all registered CommandHandlers for T.

func DispatchTo added in v0.23.0

func DispatchTo[T any](ctx context.Context, runtime *Runtime, msg T) error

DispatchTo executes a typed command against one isolated runtime.

func DispatchWith added in v0.17.0

func DispatchWith[T any](ctx context.Context, msg T, opts command.DispatchOptions) (command.DispatchReceipt, error)

func DispatchWithResult added in v0.3.0

func DispatchWithResult[T any, R any](ctx context.Context, msg T) (R, error)

func InstallDefaultRuntime added in v0.23.0

func InstallDefaultRuntime(runtime *Runtime) (func(), error)

InstallDefaultRuntime replaces the process default and returns an idempotent restore closure. Restoration is conditional so an older closure cannot overwrite a newer installation.

func Query

func Query[T any, R any](ctx context.Context, msg T) (R, error)

Query executes the single registered QueryHandler for T, returning R.

func QuerySubscriptionHook added in v0.23.0

func QuerySubscriptionHook[T any, R any](runtime *Runtime) func(any, ...runner.Option) (Subscription, error)

QuerySubscriptionHook adapts RuntimeContainer's untyped composition hook to a typed runtime query subscription.

func QueryTo added in v0.23.0

func QueryTo[T any, R any](ctx context.Context, runtime *Runtime, msg T) (R, error)

QueryTo executes a typed query against one isolated runtime.

func RegisterExecutor added in v0.17.0

func RegisterExecutor(mode command.ExecutionMode, exec CommandExecutor) error

func RegisterObservedExecutor added in v0.22.0

func RegisterObservedExecutor(mode command.ExecutionMode, exec CommandExecutor) error

RegisterObservedExecutor registers a queued executor with acceptance lifecycle instrumentation. Inline execution is already observed directly.

func Reset added in v0.13.0

func Reset()

Reset clears all command/query subscriptions.

func RunObservedCommand added in v0.22.0

func RunObservedCommand(ctx context.Context, run command.DispatchRunContext, fn func(context.Context) error) error

RunObservedCommand wraps delayed queued command execution with lifecycle and progress events using a run context captured at acceptance time.

func SetCommandRoutingMode added in v0.18.0

func SetCommandRoutingMode(mode RoutingMode, opts ...RoutingOption) error

func SetCommandRunObservers added in v0.22.0

func SetCommandRunObservers(observers ...command.CommandRunObserver)

SetCommandRunObservers replaces all registered command run observers.

func SetModeResolver added in v0.17.0

func SetModeResolver(resolver ModeResolver)

func UnregisterExecutor added in v0.17.0

func UnregisterExecutor(mode command.ExecutionMode)

Types

type CommandExecutor added in v0.17.0

type CommandExecutor interface {
	Execute(ctx context.Context, msg any, commandID string, opts command.DispatchOptions) (command.DispatchReceipt, error)
}

func ExecutorForMode added in v0.20.0

func ExecutorForMode(mode command.ExecutionMode) (CommandExecutor, bool)

func ObserveExecutor added in v0.22.0

func ObserveExecutor(exec CommandExecutor) CommandExecutor

ObserveExecutor wraps a queued executor with acceptance lifecycle events.

type ModeResolver added in v0.17.0

type ModeResolver interface {
	ResolveMode(ctx context.Context, commandID string) (mode command.ExecutionMode, found bool, err error)
}

type RoutingMode added in v0.18.0

type RoutingMode string
const (
	RoutingModeExact RoutingMode = "exact"
	RoutingModeRich  RoutingMode = "rich"
)

func CommandRoutingMode added in v0.18.0

func CommandRoutingMode() RoutingMode

type RoutingOption added in v0.18.0

type RoutingOption func(*routingConfig)

func WithRoutingMatchStrategy added in v0.18.0

func WithRoutingMatchStrategy(strategy router.MatchStrategy) RoutingOption

func WithRoutingMatcher added in v0.18.0

func WithRoutingMatcher(matcher func(pattern, topic string) bool) RoutingOption

type Runtime added in v0.23.0

type Runtime struct {
	// contains filtered or unexported fields
}

Runtime owns isolated command and query subscription state.

func DefaultRuntime added in v0.23.0

func DefaultRuntime() *Runtime

DefaultRuntime returns the concurrency-safe process default.

func NewRuntime added in v0.23.0

func NewRuntime(options ...RuntimeOption) *Runtime

func (*Runtime) AttachRegistrationProvider added in v0.23.0

func (r *Runtime) AttachRegistrationProvider(provider command.RegistrationProvider) error

AttachRegistrationProvider validates and snapshots a complete provider generation before making it visible to dynamic dispatch.

func (*Runtime) ConfigurePlacementResolver added in v0.23.0

func (r *Runtime) ConfigurePlacementResolver(resolver command.PlacementResolver) error

ConfigurePlacementResolver installs an application-owned resolver as part of one atomic provider/placement generation.

func (*Runtime) ConfigureRemoteDispatcher added in v0.23.0

func (r *Runtime) ConfigureRemoteDispatcher(remote command.RemoteDispatcher) error

ConfigureRemoteDispatcher installs or clears the transport-neutral remote port as part of one atomic runtime generation.

func (*Runtime) Dispatch added in v0.23.0

func (r *Runtime) Dispatch(ctx context.Context, kind command.HandlerKind, message any, options command.DispatchOptions) (command.DispatchOutcome, error)

Dispatch resolves a dynamic value by kind and message type, then invokes it locally. Placement is layered onto this method by routed runtime generation configuration.

func (*Runtime) InvokeLocal added in v0.23.0

func (r *Runtime) InvokeLocal(ctx context.Context, registration command.MessageRegistration, message any, options command.DispatchOptions) (command.DispatchOutcome, error)

InvokeLocal is the trusted, already-resolved local invocation boundary.

func (*Runtime) InvokeLocalByID added in v0.23.0

func (r *Runtime) InvokeLocalByID(ctx context.Context, kind command.HandlerKind, stableID string, message any, options command.DispatchOptions) (command.DispatchOutcome, error)

func (*Runtime) InvokeLocalByMessageType added in v0.23.0

func (r *Runtime) InvokeLocalByMessageType(ctx context.Context, kind command.HandlerKind, messageType string, message any, options command.DispatchOptions) (command.DispatchOutcome, error)

func (*Runtime) RegisterExecutor added in v0.23.0

func (r *Runtime) RegisterExecutor(mode command.ExecutionMode, executor CommandExecutor) error

func (*Runtime) RegistrationProvider added in v0.23.0

func (r *Runtime) RegistrationProvider() command.RegistrationProvider

func (*Runtime) ReplacePlacementPolicies added in v0.23.0

func (r *Runtime) ReplacePlacementPolicies(policies ...command.PlacementPolicy) error

ReplacePlacementPolicies validates all kind-qualified IDs and routes before atomically publishing the new resolver snapshot.

func (*Runtime) Reset added in v0.23.0

func (r *Runtime) Reset()

Reset clears subscriptions, executors, and routed configuration owned by one runtime. Existing subscription handles remain safe and idempotent.

func (*Runtime) RoutedReady added in v0.23.0

func (r *Runtime) RoutedReady() error

RoutedReady reports whether stable-ID and dynamic operations have a complete registration generation. Typed local dispatch does not require readiness.

func (*Runtime) UnregisterExecutor added in v0.23.0

func (r *Runtime) UnregisterExecutor(mode command.ExecutionMode)

type RuntimeOption added in v0.23.0

type RuntimeOption func(*Runtime)

type Subscription

type Subscription interface {
	Unsubscribe()
}

func AddCommandRunObserver added in v0.22.0

func AddCommandRunObserver(observer command.CommandRunObserver) Subscription

AddCommandRunObserver registers a command run observer and returns an idempotent unsubscribe handle.

func SubscribeCommand

func SubscribeCommand[T any](cmd command.Commander[T], runnerOpts ...runner.Option) Subscription

Subscribe a CommandHandler for a particular message type T. TODO: should this return an error?!

func SubscribeCommandFunc

func SubscribeCommandFunc[T any](handler command.CommandFunc[T], runnerOpts ...runner.Option) Subscription

func SubscribeCommandTo added in v0.23.0

func SubscribeCommandTo[T any](runtime *Runtime, cmd command.Commander[T], runnerOpts ...runner.Option) Subscription

func SubscribeQuery

func SubscribeQuery[T any, R any](qry command.Querier[T, R], runnerOpts ...runner.Option) Subscription

Subscribe a QueryHandler for a particular message type T, R.

func SubscribeQueryFunc

func SubscribeQueryFunc[T any, R any](qry command.QueryFunc[T, R], runnerOpts ...runner.Option) Subscription

func SubscribeQueryTo added in v0.23.0

func SubscribeQueryTo[T any, R any](runtime *Runtime, qry command.Querier[T, R], runnerOpts ...runner.Option) Subscription

Jump to

Keyboard shortcuts

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