message

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2019 License: MIT Imports: 5 Imported by: 12

Documentation

Overview

Package message provides tools for manipulating Dogma messages.

Index

Constants

This section is empty.

Variables

Directions is a slice of the valid message direcations.

Roles is a slice of the valid message roles.

Functions

func ToString

func ToString(m dogma.Message) string

ToString returns a string representation of m.

If m implements Stringer, it returns m.MessageString(). Otherwise, if m implements fmt.Stringer, it returns m.String().

Finally, if m does not implement either of these interfaces, it returns the standard Go "%v" representation of the message.

Types

type Correlation

type Correlation struct {
	// MessageID is a unique identifier for the message.
	MessageID string

	// CausationID is the ID of the message that was being handled when the message
	// identified by MessageID was produced.
	CausationID string

	// CorrelationID is the ID of the "root" message that entered the application
	// to cause the message identified by MessageID, either directly or indirectly.
	CorrelationID string
}

Correlation is holds identifiers for a specific message.

func NewCorrelation

func NewCorrelation(id string) Correlation

NewCorrelation returns a correlation for the "root" message with the given ID.

func (Correlation) IsCausedBy

func (c Correlation) IsCausedBy(p Correlation) bool

IsCausedBy returns true if c.MessageID is directly caused by p.

func (Correlation) IsCorrelatedWith

func (c Correlation) IsCorrelatedWith(p Correlation) bool

IsCorrelatedWith returns true if c.MessageID is correlated with p.

func (Correlation) IsRoot

func (c Correlation) IsRoot() bool

IsRoot returns true if this message is the "root" of a message tree.

func (Correlation) MustValidate

func (c Correlation) MustValidate()

MustValidate panics if c is not a valid correlation.

func (Correlation) New

func (c Correlation) New(id string) Correlation

New returns a correlation for a message caused by c.MessageID.

func (Correlation) Validate added in v0.5.1

func (c Correlation) Validate() error

Validate returns an error if c is not a valid correlation.

type Direction

type Direction string

Direction is an enumeration of the "direction" a message is flowing, relative to a handler.

const (
	// InboundDirection means a message is being passed into a handler, that is,
	// being handled.
	InboundDirection Direction = "inbound"

	// OutboundDirection means a message was produced by a handler.
	OutboundDirection Direction = "outbound"
)

func (Direction) MustBe

func (d Direction) MustBe(x Direction)

MustBe panics if r is not equal to x.

func (Direction) MustNotBe

func (d Direction) MustNotBe(x Direction)

MustNotBe panics if r is equal to x.

func (Direction) MustValidate

func (d Direction) MustValidate()

MustValidate panics if r is not a valid message direction.

func (Direction) String

func (d Direction) String() string

func (Direction) Validate added in v0.5.1

func (d Direction) Validate() error

Validate returns an error if r is not a valid message direction.

type Role

type Role string

Role is an enumeration of the roles a message can perform within an engine.

const (
	// CommandRole is the role for command messages.
	CommandRole Role = "command"

	// EventRole is the role for event messages.
	EventRole Role = "event"

	// TimeoutRole is the role for timeout messages.
	TimeoutRole Role = "timeout"
)

func (Role) Is

func (r Role) Is(roles ...Role) bool

Is returns true if r is one of the given roles.

func (Role) Marker

func (r Role) Marker() string

Marker returns a character that identifies the message role when displaying message types.

func (Role) MustBe

func (r Role) MustBe(roles ...Role)

MustBe panics if r is not one of the given roles.

func (Role) MustNotBe

func (r Role) MustNotBe(roles ...Role)

MustNotBe panics if r is one of the given roles.

func (Role) MustValidate

func (r Role) MustValidate()

MustValidate panics if r is not a valid message role.

func (Role) String

func (r Role) String() string

func (Role) Validate added in v0.5.1

func (r Role) Validate() error

Validate return an error if r is not a valid message role.

type RoleMap added in v0.3.0

type RoleMap map[Type]Role

RoleMap is a map of message type to role. It implements the TypeContainer interface.

func (RoleMap) Add added in v0.3.0

func (rm RoleMap) Add(t Type, r Role) bool

Add maps t to r.

It returns true if the mapping was added, or false if the map already contained the type.

func (RoleMap) AddM added in v0.3.0

func (rm RoleMap) AddM(m dogma.Message, r Role) bool

AddM adds TypeOf(m) to rm.

It returns true if the mapping was added, or false if the map already contained the type.

func (RoleMap) Has added in v0.3.0

func (rm RoleMap) Has(t Type) bool

Has returns true if rm contains t.

func (RoleMap) HasM added in v0.3.0

func (rm RoleMap) HasM(m dogma.Message) bool

HasM returns true if rm contains TypeOf(m).

func (RoleMap) Remove added in v0.3.0

func (rm RoleMap) Remove(t Type) bool

Remove removes t from rm.

It returns true if the type was removed, or false if the set did not contain the type.

func (RoleMap) RemoveM added in v0.3.0

func (rm RoleMap) RemoveM(m dogma.Message) bool

RemoveM removes TypeOf(m) from rm.

It returns true if the type was removed, or false if the set did not contain the type.

type Stringer

type Stringer interface {
	// MessageString returns a human-readable description of the message.
	MessageString() string
}

Stringer is an interface implemented by messages that can describe themselves.

It can be used to provide a more specific message description for message types that already implement fmt.Stringer, such as when the message implementations are generated Protocol Buffers structs.

type Type

type Type interface {
	// ReflectType returns the reflect.Type for this message type.
	ReflectType() reflect.Type

	// String returns a human-readable name for the message type.
	// Note that this representation may not be globally unique.
	String() string
}

Type is a value that identifies the type of a message.

func TypeOf

func TypeOf(m dogma.Message) Type

TypeOf returns the message type of m.

type TypeContainer added in v0.3.0

type TypeContainer interface {
	// Has returns true if t is in the container.
	Has(t Type) bool

	// HasM returns true if TypeOf(m) is in the container.
	HasM(m dogma.Message) bool
}

TypeContainer is an interface for containers of message types.

type TypeSet

type TypeSet map[Type]struct{}

TypeSet is a collection of distinct message types. It implements the TypeContainer interface.

func NewTypeSet

func NewTypeSet(types ...Type) TypeSet

NewTypeSet returns a TypeSet containing the given types.

func TypesOf

func TypesOf(messages ...dogma.Message) TypeSet

TypesOf returns a type set containing the types of the given messages.

func (TypeSet) Add

func (s TypeSet) Add(t Type) bool

Add adds t to s.

It returns true if the type was added, or false if the set already contained the type.

func (TypeSet) AddM

func (s TypeSet) AddM(m dogma.Message) bool

AddM adds TypeOf(m) to s.

It returns true if the type was added, or false if the set already contained the type.

func (TypeSet) Has

func (s TypeSet) Has(t Type) bool

Has returns true if s contains t.

func (TypeSet) HasM

func (s TypeSet) HasM(m dogma.Message) bool

HasM returns true if s contains TypeOf(m).

func (TypeSet) Remove

func (s TypeSet) Remove(t Type) bool

Remove removes t from s.

It returns true if the type was removed, or false if the set did not contain the type.

func (TypeSet) RemoveM

func (s TypeSet) RemoveM(m dogma.Message) bool

RemoveM removes TypeOf(m) from s.

It returns true if the type was removed, or false if the set did not contain the type.

Jump to

Keyboard shortcuts

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