envelope

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package envelope packs Dogma messages into envelopes and unpacks them again.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Unpack

func Unpack[T dogma.Message](env *envelopepb.Envelope) (T, error)

Unpack returns the message contained within an envelope.

T may be a message interface such as dogma.Command or a concrete message type.

func WithBaggage

WithBaggage adds x to the envelope's baggage.

Baggage applies to the envelope being packed and is inherited by downstream messages in the causal chain.

func WithExtension

WithExtension adds x to the envelope's extensions.

Extensions apply only to the envelope being packed; they are not inherited by downstream messages in the causal chain.

Types

type EffectPacker

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

An EffectPacker packs messages produced while handling a specific causal message into a envelopepb.MultiEnvelope.

func (*EffectPacker) PackCommand

func (p *EffectPacker) PackCommand(m dogma.Command, options ...PackEffectCommandOption) *envelopepb.Envelope

PackCommand appends m to the multi-envelope under construction.

func (*EffectPacker) PackDeadline

func (p *EffectPacker) PackDeadline(m dogma.Deadline, options ...PackEffectDeadlineOption) *envelopepb.Envelope

PackDeadline appends m to the multi-envelope under construction.

func (*EffectPacker) PackEvent

func (p *EffectPacker) PackEvent(m dogma.Event, options ...PackEffectEventOption) *envelopepb.Envelope

PackEvent appends m to the multi-envelope under construction.

func (*EffectPacker) Seal

func (p *EffectPacker) Seal() (*envelopepb.MultiEnvelope, bool)

Seal returns a envelopepb.MultiEnvelope containing all packed messages, or false if no messages were packed.

type PackCommandOption

type PackCommandOption interface {
	// contains filtered or unexported methods
}

PackCommandOption is an option that modifies the behavior of Packer.PackCommand.

func WithIdempotencyKey

func WithIdempotencyKey(key string) PackCommandOption

WithIdempotencyKey sets the idempotency key of a command packed via Packer.PackCommand.

type PackEffectCommandOption

type PackEffectCommandOption interface {
	// contains filtered or unexported methods
}

PackEffectCommandOption is an option that modifies the behavior of EffectPacker.PackCommand.

type PackEffectDeadlineOption

type PackEffectDeadlineOption interface {
	// contains filtered or unexported methods
}

PackEffectDeadlineOption is an option that modifies the behavior of EffectPacker.PackDeadline.

func WithScheduledFor

func WithScheduledFor(t time.Time) PackEffectDeadlineOption

WithScheduledFor sets the time at which a deadline is reached when packed via EffectPacker.PackDeadline.

type PackEffectEventOption

type PackEffectEventOption interface {
	// contains filtered or unexported methods
}

PackEffectEventOption is an option that modifies the behavior of EffectPacker.PackEvent.

type PackEffectsOption

type PackEffectsOption interface {
	// contains filtered or unexported methods
}

PackEffectsOption is an option that modifies the behavior of Packer.PackEffects.

func WithInstanceID

func WithInstanceID(id string) PackEffectsOption

WithInstanceID sets the aggregate or process instance ID that is the source of messages packed via Packer.PackEffects.

type Packer

type Packer struct {
	// Site is the (optional) identity of the site that the source application
	// is running within.
	//
	// The site is used to disambiguate between messages from different
	// installations of the same application.
	Site *identitypb.Identity

	// Application is the identity of the application that is the source of the
	// messages.
	Application *identitypb.Identity

	// GenerateID is a function used to generate new message IDs.
	//
	// If it is nil, a random UUID is generated.
	GenerateID func() *uuidpb.UUID

	// Now is a function used to get the current time. If it is nil, time.Now()
	// is used.
	Now func() time.Time
}

A Packer puts messages into envelopes.

func (*Packer) PackCommand

func (p *Packer) PackCommand(m dogma.Command, options ...PackCommandOption) *envelopepb.Envelope

PackCommand returns an envelope containing the given command.

func (*Packer) PackEffects

func (p *Packer) PackEffects(
	cause *envelopepb.Envelope,
	h *identitypb.Identity,
	options ...PackEffectsOption,
) *EffectPacker

PackEffects returns an EffectPacker that packs messages produced by h while handling cause.

Jump to

Keyboard shortcuts

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