envelopepb

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package envelopepb provides the "well-known" Envelope type for representing message envelopes as Protocol Buffers messages.

Index

Constants

This section is empty.

Variables

View Source
var File_github_com_dogmatiq_enginekit_protobuf_envelopepb_envelope_proto protoreflect.FileDescriptor

Functions

This section is empty.

Types

type Envelope

type Envelope struct {

	// MessageId is a unique identifier for the message in this envelope.
	MessageId *uuidpb.UUID `protobuf:"bytes,1,opt,name=message_id,json=messageId,proto3" json:"message_id,omitempty"`
	// CausationId is the (optional) ID of the message that was the direct cause
	// of the message in this envelope.
	//
	// If it is the zero-value, the message was not caused by any other message.
	CausationId *uuidpb.UUID `protobuf:"bytes,2,opt,name=causation_id,json=causationId,proto3" json:"causation_id,omitempty"`
	// CorrelationId is the (optional) ID of the first ancestor of the message in
	// this envelope that was not caused by another message.
	//
	// If it is the zero-value, the message was not caused by any other message.
	CorrelationId *uuidpb.UUID `protobuf:"bytes,3,opt,name=correlation_id,json=correlationId,proto3" json:"correlation_id,omitempty"`
	// SourceSite 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.
	SourceSite *identitypb.Identity `protobuf:"bytes,4,opt,name=source_site,json=sourceSite,proto3" json:"source_site,omitempty"`
	// SourceApplication is the identity of the Dogma application that produced
	// the message in this envelope.
	SourceApplication *identitypb.Identity `protobuf:"bytes,5,opt,name=source_application,json=sourceApplication,proto3" json:"source_application,omitempty"`
	// SourceHandler is the identity of the Dogma handler that produced the
	// message in this envelope.
	//
	// It is the zero-value if the message was not produced by a handler.
	SourceHandler *identitypb.Identity `protobuf:"bytes,6,opt,name=source_handler,json=sourceHandler,proto3" json:"source_handler,omitempty"`
	// SourceInstanceId is the ID of the aggregate or process instance that
	// produced the message in this envelope.
	//
	// It is empty if the message was not produced by an aggregate or process
	// handler.
	SourceInstanceId string `protobuf:"bytes,7,opt,name=source_instance_id,json=sourceInstanceId,proto3" json:"source_instance_id,omitempty"`
	// CreatedAt is the time at which the envelope was created.
	//
	// This is typically the point at which the message first enters the engine.
	CreatedAt *timestamppb.Timestamp `protobuf:"bytes,8,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"`
	// ScheduledFor is the time at which a timeout message is scheduled to occur.
	//
	// It is the zero-value if the message is a command or event.
	ScheduledFor *timestamppb.Timestamp `protobuf:"bytes,9,opt,name=scheduled_for,json=scheduledFor,proto3" json:"scheduled_for,omitempty"`
	// Description is a human-readable description of the message.
	Description string `protobuf:"bytes,10,opt,name=description,proto3" json:"description,omitempty"`
	// MediaType is a MIME media-type describing the content and encoding of the
	// binary message data.
	MediaType string `protobuf:"bytes,11,opt,name=media_type,json=mediaType,proto3" json:"media_type,omitempty"`
	// Data is the binary message data.
	//
	// The data format is described by MediaType, the allowed values of both are
	// outside the scope of this specification.
	Data []byte `protobuf:"bytes,12,opt,name=data,proto3" json:"data,omitempty"`
	// Attributes is a set of arbitrary key/value pairs that provide additional
	// information about the message.
	//
	// Keys beginning with "_" are reserved for use by the enginekit module. All
	// other keys SHOULD use reverse-domain notation, e.g. "com.example.some-key".
	Attributes map[string]string `` /* 162-byte string literal not displayed */
	// contains filtered or unexported fields
}

Envelope is a container for a Dogma message and its meta-data.

func (*Envelope) Descriptor deprecated

func (*Envelope) Descriptor() ([]byte, []int)

Deprecated: Use Envelope.ProtoReflect.Descriptor instead.

func (*Envelope) GetAttributes

func (x *Envelope) GetAttributes() map[string]string

func (*Envelope) GetCausationId

func (x *Envelope) GetCausationId() *uuidpb.UUID

func (*Envelope) GetCorrelationId

func (x *Envelope) GetCorrelationId() *uuidpb.UUID

func (*Envelope) GetCreatedAt

func (x *Envelope) GetCreatedAt() *timestamppb.Timestamp

func (*Envelope) GetData

func (x *Envelope) GetData() []byte

func (*Envelope) GetDescription

func (x *Envelope) GetDescription() string

func (*Envelope) GetMediaType

func (x *Envelope) GetMediaType() string

func (*Envelope) GetMessageId

func (x *Envelope) GetMessageId() *uuidpb.UUID

func (*Envelope) GetScheduledFor

func (x *Envelope) GetScheduledFor() *timestamppb.Timestamp

func (*Envelope) GetSourceApplication

func (x *Envelope) GetSourceApplication() *identitypb.Identity

func (*Envelope) GetSourceHandler

func (x *Envelope) GetSourceHandler() *identitypb.Identity

func (*Envelope) GetSourceInstanceId

func (x *Envelope) GetSourceInstanceId() string

func (*Envelope) GetSourceSite

func (x *Envelope) GetSourceSite() *identitypb.Identity

func (*Envelope) ProtoMessage

func (*Envelope) ProtoMessage()

func (*Envelope) ProtoReflect

func (x *Envelope) ProtoReflect() protoreflect.Message

func (*Envelope) Reset

func (x *Envelope) Reset()

func (*Envelope) SetAttributes

func (x *Envelope) SetAttributes(v map[string]string)

SetAttributes sets the x.Attributes field to v, then returns x.

func (*Envelope) SetCausationId

func (x *Envelope) SetCausationId(v *uuidpb.UUID)

SetCausationId sets the x.CausationId field to v, then returns x.

func (*Envelope) SetCorrelationId

func (x *Envelope) SetCorrelationId(v *uuidpb.UUID)

SetCorrelationId sets the x.CorrelationId field to v, then returns x.

func (*Envelope) SetCreatedAt

func (x *Envelope) SetCreatedAt(v *timestamppb.Timestamp)

SetCreatedAt sets the x.CreatedAt field to v, then returns x.

func (*Envelope) SetData

func (x *Envelope) SetData(v []byte)

SetData sets the x.Data field to v, then returns x.

func (*Envelope) SetDescription

func (x *Envelope) SetDescription(v string)

SetDescription sets the x.Description field to v, then returns x.

func (*Envelope) SetMediaType

func (x *Envelope) SetMediaType(v string)

SetMediaType sets the x.MediaType field to v, then returns x.

func (*Envelope) SetMessageId

func (x *Envelope) SetMessageId(v *uuidpb.UUID)

SetMessageId sets the x.MessageId field to v, then returns x.

func (*Envelope) SetScheduledFor

func (x *Envelope) SetScheduledFor(v *timestamppb.Timestamp)

SetScheduledFor sets the x.ScheduledFor field to v, then returns x.

func (*Envelope) SetSourceApplication

func (x *Envelope) SetSourceApplication(v *identitypb.Identity)

SetSourceApplication sets the x.SourceApplication field to v, then returns x.

func (*Envelope) SetSourceHandler

func (x *Envelope) SetSourceHandler(v *identitypb.Identity)

SetSourceHandler sets the x.SourceHandler field to v, then returns x.

func (*Envelope) SetSourceInstanceId

func (x *Envelope) SetSourceInstanceId(v string)

SetSourceInstanceId sets the x.SourceInstanceId field to v, then returns x.

func (*Envelope) SetSourceSite

func (x *Envelope) SetSourceSite(v *identitypb.Identity)

SetSourceSite sets the x.SourceSite field to v, then returns x.

func (*Envelope) String

func (x *Envelope) String() string

func (*Envelope) Validate

func (x *Envelope) Validate() error

Validate returns an error if x is not well-formed.

Well-formedness means that all compulsory fields are populated, and that no incompatible fields are populated.

It is intentially fairly permissive, so that message meta-data can be obtained even if the message is unable to be handled.

It does not perform "deep" validation, such as ensuring messages, times, etc can be unmarshaled.

type EnvelopeBuilder

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

func NewEnvelopeBuilder

func NewEnvelopeBuilder() *EnvelopeBuilder

NewEnvelopeBuilder returns a builder that constructs Envelope messages.

func (*EnvelopeBuilder) Build

func (b *EnvelopeBuilder) Build() *Envelope

Build returns a new Envelope containing the values configured via the builder.

Each call returns a new message, such that future changes to the builder do not modify previously constructed messages.

func (*EnvelopeBuilder) From

From configures the builder to use x as the prototype for new messages, then returns b.

It performs a shallow copy of x, such that any changes made via the builder do not modify x. It does not make a copy of the field values themselves.

func (*EnvelopeBuilder) WithAttributes

func (b *EnvelopeBuilder) WithAttributes(v map[string]string) *EnvelopeBuilder

WithAttributes configures the builder to set the Attributes field to v, then returns b.

func (*EnvelopeBuilder) WithCausationId

func (b *EnvelopeBuilder) WithCausationId(v *uuidpb.UUID) *EnvelopeBuilder

WithCausationId configures the builder to set the CausationId field to v, then returns b.

func (*EnvelopeBuilder) WithCorrelationId

func (b *EnvelopeBuilder) WithCorrelationId(v *uuidpb.UUID) *EnvelopeBuilder

WithCorrelationId configures the builder to set the CorrelationId field to v, then returns b.

func (*EnvelopeBuilder) WithCreatedAt

func (b *EnvelopeBuilder) WithCreatedAt(v *timestamppb.Timestamp) *EnvelopeBuilder

WithCreatedAt configures the builder to set the CreatedAt field to v, then returns b.

func (*EnvelopeBuilder) WithData

func (b *EnvelopeBuilder) WithData(v []byte) *EnvelopeBuilder

WithData configures the builder to set the Data field to v, then returns b.

func (*EnvelopeBuilder) WithDescription

func (b *EnvelopeBuilder) WithDescription(v string) *EnvelopeBuilder

WithDescription configures the builder to set the Description field to v, then returns b.

func (*EnvelopeBuilder) WithMediaType

func (b *EnvelopeBuilder) WithMediaType(v string) *EnvelopeBuilder

WithMediaType configures the builder to set the MediaType field to v, then returns b.

func (*EnvelopeBuilder) WithMessageId

func (b *EnvelopeBuilder) WithMessageId(v *uuidpb.UUID) *EnvelopeBuilder

WithMessageId configures the builder to set the MessageId field to v, then returns b.

func (*EnvelopeBuilder) WithScheduledFor

func (b *EnvelopeBuilder) WithScheduledFor(v *timestamppb.Timestamp) *EnvelopeBuilder

WithScheduledFor configures the builder to set the ScheduledFor field to v, then returns b.

func (*EnvelopeBuilder) WithSourceApplication

func (b *EnvelopeBuilder) WithSourceApplication(v *identitypb.Identity) *EnvelopeBuilder

WithSourceApplication configures the builder to set the SourceApplication field to v, then returns b.

func (*EnvelopeBuilder) WithSourceHandler

func (b *EnvelopeBuilder) WithSourceHandler(v *identitypb.Identity) *EnvelopeBuilder

WithSourceHandler configures the builder to set the SourceHandler field to v, then returns b.

func (*EnvelopeBuilder) WithSourceInstanceId

func (b *EnvelopeBuilder) WithSourceInstanceId(v string) *EnvelopeBuilder

WithSourceInstanceId configures the builder to set the SourceInstanceId field to v, then returns b.

func (*EnvelopeBuilder) WithSourceSite

func (b *EnvelopeBuilder) WithSourceSite(v *identitypb.Identity) *EnvelopeBuilder

WithSourceSite configures the builder to set the SourceSite field to v, then returns b.

type PackOption added in v0.12.1

type PackOption func(*Envelope)

PackOption is an option that alters the behavior of a Pack operation.

func WithCause added in v0.12.1

func WithCause(env *Envelope) PackOption

WithCause sets env as the "cause" of the message being packed.

func WithCreatedAt added in v0.12.1

func WithCreatedAt(t time.Time) PackOption

WithCreatedAt sets the creation time of a message.

func WithHandler added in v0.12.1

func WithHandler(h *identitypb.Identity) PackOption

WithHandler sets h as the identity of the handler that is the source of the message.

func WithInstanceID added in v0.12.1

func WithInstanceID(id string) PackOption

WithInstanceID sets the aggregate or process instance ID that is the source of the message.

func WithScheduledFor added in v0.12.1

func WithScheduledFor(t time.Time) PackOption

WithScheduledFor sets the scheduled time of a timeout message.

type Packer added in v0.12.1

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

	// Marshaler is used to marshal messages into envelopes.
	Marshaler marshaler.Marshaler

	// 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) Pack added in v0.12.1

func (p *Packer) Pack(m dogma.Message, options ...PackOption) *Envelope

Pack returns an envelope containing the given message.

func (*Packer) Unpack added in v0.12.1

func (p *Packer) Unpack(env *Envelope) (dogma.Message, error)

Unpack returns the message contained within an envelope.

type Transcoder added in v0.12.1

type Transcoder struct {
	// MediaTypes is a map of the message's type to a list of supported
	// media-types, in order of preference.
	MediaTypes map[reflect.Type][]string

	// Marshaler is the marshaler to use to unmarshal and marshal messages.
	Marshaler marshaler.Marshaler
}

Transcoder re-encodes messages to different media-types on the fly.

func (*Transcoder) Transcode added in v0.12.1

func (t *Transcoder) Transcode(env *Envelope) (*Envelope, bool, error)

Transcode re-encodes the message in env to one of the supported media-types.

Jump to

Keyboard shortcuts

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