messages

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MetaCausationID should be set on a context where a command
	// is called, this will allow us to pull the command id out and
	// set it as the causation ID.
	// Read more: https://blog.arkency.com/correlation-id-and-causation-id-in-evented-systems/
	MetaCausationID metaKey = "causation_id"

	// MetaCorrelationID if another event caused this new event we should
	// set that as the correlation id on the event's metadata.
	// Read more: https://blog.arkency.com/correlation-id-and-causation-id-in-evented-systems/
	MetaCorrelationID metaKey = "correlation_id"

	// MetaAggregateID is the identifier of an aggregate, used when using event sourcing.
	MetaAggregateID metaKey = "aggregate_id"

	// MetaAggregateVersion should be set on an event for the version it is targeting, for
	// example if you've loaded an aggregate at version 6 the next version should be 7.
	// Versions start from 1!
	MetaAggregateVersion metaKey = "aggregate_version"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

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

Command describes something that has happened.

func CommandWithMetadata

func CommandWithMetadata(c *Command, m map[string]interface{}) *Command

CommandWithMetadata returns an command copied from the previous command with the updated metadata.

func CommandWithVersion

func CommandWithVersion(c *Command, v uint64) *Command

CommandWithVersion returns an command copied from the previous command with the updated version.

func NewCommand

func NewCommand(id, name string, data interface{}, metadata map[string]interface{}, version uint64, created time.Time) *Command

NewCommand will return an immutable command.

func NewCommandFromContext

func NewCommandFromContext(ctx context.Context, id, name string, data interface{}, metadata map[string]interface{}, version uint64, created time.Time) *Command

NewCommandFromContext will return an immutable command, filling metadata with any information that we know can be added to commands such as causation id.

func (*Command) Created

func (c *Command) Created() time.Time

Created returns the time the Command was created.

func (*Command) Data

func (c *Command) Data() interface{}

Data will return information related to the command.

func (*Command) MessageID

func (c *Command) MessageID() string

MessageID returns the id of the message.

func (*Command) MessageName

func (c *Command) MessageName() string

MessageName returns the name of the message.

func (*Command) Metadata

func (c *Command) Metadata() map[string]interface{}

Metadata will return metadata about the command.

func (*Command) Version

func (c *Command) Version() uint64

Version returns the version of the command.

type DomainMessage

type DomainMessage struct {
	// Identitifer for message.
	MessageId string `protobuf:"bytes,1,opt,name=message_id,json=messageId,proto3" json:"message_id,omitempty"`
	// The name of the message.
	MessageName string `protobuf:"bytes,2,opt,name=message_name,json=messageName,proto3" json:"message_name,omitempty"`
	// The message payload.
	Data []byte `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"`
	// Metadata associated to the message.
	Metadata map[string][]byte `` /* 157-byte string literal not displayed */
	// The version of the domain message.
	Version uint64 `protobuf:"varint,5,opt,name=version,proto3" json:"version,omitempty"`
	// When the domain message was first created.
	Created              *timestamp.Timestamp `protobuf:"bytes,6,opt,name=created,proto3" json:"created,omitempty"`
	XXX_NoUnkeyedLiteral struct{}             `json:"-"`
	XXX_unrecognized     []byte               `json:"-"`
	XXX_sizecache        int32                `json:"-"`
}

Used to seralise messages for storaging and transfering.

func (*DomainMessage) Descriptor

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

func (*DomainMessage) GetCreated

func (m *DomainMessage) GetCreated() *timestamp.Timestamp

func (*DomainMessage) GetData

func (m *DomainMessage) GetData() []byte

func (*DomainMessage) GetMessageId

func (m *DomainMessage) GetMessageId() string

func (*DomainMessage) GetMessageName

func (m *DomainMessage) GetMessageName() string

func (*DomainMessage) GetMetadata

func (m *DomainMessage) GetMetadata() map[string][]byte

func (*DomainMessage) GetVersion

func (m *DomainMessage) GetVersion() uint64

func (*DomainMessage) ProtoMessage

func (*DomainMessage) ProtoMessage()

func (*DomainMessage) Reset

func (m *DomainMessage) Reset()

func (*DomainMessage) String

func (m *DomainMessage) String() string

func (*DomainMessage) XXX_DiscardUnknown

func (m *DomainMessage) XXX_DiscardUnknown()

func (*DomainMessage) XXX_Marshal

func (m *DomainMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*DomainMessage) XXX_Merge

func (m *DomainMessage) XXX_Merge(src proto.Message)

func (*DomainMessage) XXX_Size

func (m *DomainMessage) XXX_Size() int

func (*DomainMessage) XXX_Unmarshal

func (m *DomainMessage) XXX_Unmarshal(b []byte) error

type Event

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

Event describes something that has happened.

func EventWithMetadata

func EventWithMetadata(e *Event, m map[string]interface{}) *Event

EventWithMetadata returns an event copied from the previous event with the updated metadata.

func EventWithVersion

func EventWithVersion(e *Event, v uint64) *Event

EventWithVersion returns an event copied from the previous event with the updated version.

func NewAggregateEvent

func NewAggregateEvent(ctx context.Context, aggregateID string, aggregateVersion uint64, eventName string, data interface{}) *Event

NewAggregateEvent created a new event for an aggregate.

func NewEvent

func NewEvent(id, name string, data interface{}, metadata map[string]interface{}, version uint64, created time.Time) *Event

NewEvent will return an immutable event.

func NewEventFromContext

func NewEventFromContext(ctx context.Context, id, name string, data interface{}, metadata map[string]interface{}, version uint64, created time.Time) *Event

NewEventFromContext will return an immutable event, filling metadata with any information that we know can be added to events such as causation id.

func (*Event) Created

func (e *Event) Created() time.Time

Created returns the time the event was created.

func (*Event) Data

func (e *Event) Data() interface{}

Data will return information related to the event.

func (*Event) MessageID

func (e *Event) MessageID() string

MessageID returns the id of the message.

func (*Event) MessageName

func (e *Event) MessageName() string

MessageName returns the name of the message.

func (*Event) Metadata

func (e *Event) Metadata() map[string]interface{}

Metadata will return metadata about the event.

func (*Event) Version

func (e *Event) Version() uint64

Version returns the version of the event.

type JSONMessage

type JSONMessage struct {
	MessageID   string                 `json:"message_id"`
	MessageName string                 `json:"message_name"`
	Data        interface{}            `json:"data"`
	Metadata    map[string]interface{} `json:"metadata"`
	Version     uint64                 `json:"version"`
	Created     string                 `json:"created_at"`
}

type JSONMessageFactory

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

func NewJSONMessageFactory

func NewJSONMessageFactory() *JSONMessageFactory

NewJSONMessageFactory will return a new message factory that serializes and unserialises JSON payloads.

func (*JSONMessageFactory) Build

func (f *JSONMessageFactory) Build(msgName string, pl []byte) (interface{}, bool)

Build ...

func (*JSONMessageFactory) Builds

func (f *JSONMessageFactory) Builds(name string, factory dataTypeFactory)

Builds ...

func (*JSONMessageFactory) Serialize

func (f *JSONMessageFactory) Serialize(m Message) ([]byte, error)

Serialize ...

func (*JSONMessageFactory) Unserialize

func (f *JSONMessageFactory) Unserialize(m []byte) (Message, error)

Unserialize ...

type JSONMessageWrapper

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

func (*JSONMessageWrapper) Created

func (m *JSONMessageWrapper) Created() time.Time

Created ...

func (*JSONMessageWrapper) Data

func (m *JSONMessageWrapper) Data() interface{}

Data ...

func (*JSONMessageWrapper) MessageID

func (m *JSONMessageWrapper) MessageID() string

MessageID ...

func (*JSONMessageWrapper) MessageName

func (m *JSONMessageWrapper) MessageName() string

MessageName ...

func (*JSONMessageWrapper) Metadata

func (m *JSONMessageWrapper) Metadata() map[string]interface{}

Metadata ...

func (*JSONMessageWrapper) Version

func (m *JSONMessageWrapper) Version() uint64

Version ...

type Message

type Message interface {
	// MessageID returns the id of the message.
	MessageID() string

	// MessageName returns the name of the message.
	MessageName() string

	// Data will return information related to the event.
	Data() interface{}

	// Metadata will return metadata about the event.
	Metadata() map[string]interface{}

	// Version returns the version of the event.
	Version() uint64

	// Created returns the time the event was created.
	Created() time.Time
}

Message provides base functionality to commands, events and queries.

type MessageFactory

type MessageFactory interface {
	Serialize(Message) ([]byte, error)
	Unserialize([]byte) (Message, error)
}

MessageFactory ...

type PayloadBuilder

type PayloadBuilder interface {
	Build(msgName string, pl []byte) (interface{}, bool)
	Builds(msgName string, with dataTypeFactory)
}

PayloadBuilder ...

type ProtoMessageFactory

type ProtoMessageFactory struct{}

func NewProtoMessageFactory

func NewProtoMessageFactory() *ProtoMessageFactory

NewProtoMessageFactory will return a new message factory that serializes and unserialises Proto payloads.

func (*ProtoMessageFactory) Build

func (f *ProtoMessageFactory) Build(msgName string, pl []byte) (interface{}, bool)

Build ...

func (*ProtoMessageFactory) Builds

func (f *ProtoMessageFactory) Builds(name string, factory dataTypeFactory)

Builds is obsolete for protobuff as the generated Go library registers the messages itself.

func (*ProtoMessageFactory) Serialize

func (f *ProtoMessageFactory) Serialize(m Message) ([]byte, error)

Serialize ...

func (*ProtoMessageFactory) Unserialize

func (f *ProtoMessageFactory) Unserialize(m []byte) (Message, error)

Unserialize ...

type ProtoMessageWrapper

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

func (*ProtoMessageWrapper) Created

func (m *ProtoMessageWrapper) Created() time.Time

Created ...

func (*ProtoMessageWrapper) Data

func (m *ProtoMessageWrapper) Data() interface{}

Data ...

func (*ProtoMessageWrapper) MessageID

func (m *ProtoMessageWrapper) MessageID() string

MessageID ...

func (*ProtoMessageWrapper) MessageName

func (m *ProtoMessageWrapper) MessageName() string

MessageName ...

func (*ProtoMessageWrapper) Metadata

func (m *ProtoMessageWrapper) Metadata() map[string]interface{}

Metadata ...

func (*ProtoMessageWrapper) Version

func (m *ProtoMessageWrapper) Version() uint64

Version ...

type TestPayload

type TestPayload struct {
	AString              string   `protobuf:"bytes,1,opt,name=a_string,json=aString,proto3" json:"a_string,omitempty"`
	AInt                 int64    `protobuf:"varint,2,opt,name=a_int,json=aInt,proto3" json:"a_int,omitempty"`
	ABool                bool     `protobuf:"varint,3,opt,name=a_bool,json=aBool,proto3" json:"a_bool,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*TestPayload) Descriptor

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

func (*TestPayload) GetABool

func (m *TestPayload) GetABool() bool

func (*TestPayload) GetAInt

func (m *TestPayload) GetAInt() int64

func (*TestPayload) GetAString

func (m *TestPayload) GetAString() string

func (*TestPayload) ProtoMessage

func (*TestPayload) ProtoMessage()

func (*TestPayload) Reset

func (m *TestPayload) Reset()

func (*TestPayload) String

func (m *TestPayload) String() string

func (*TestPayload) XXX_DiscardUnknown

func (m *TestPayload) XXX_DiscardUnknown()

func (*TestPayload) XXX_Marshal

func (m *TestPayload) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*TestPayload) XXX_Merge

func (m *TestPayload) XXX_Merge(src proto.Message)

func (*TestPayload) XXX_Size

func (m *TestPayload) XXX_Size() int

func (*TestPayload) XXX_Unmarshal

func (m *TestPayload) XXX_Unmarshal(b []byte) error

Jump to

Keyboard shortcuts

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