Documentation
¶
Overview ¶
Package message provides tools for manipulating Dogma messages.
Index ¶
- Variables
- func Description(m dogma.Message) string
- type Correlation
- type Describer
- type Direction
- type Role
- type RoleMap
- func (rm RoleMap) Add(t Type, r Role) bool
- func (rm RoleMap) AddM(m dogma.Message, r Role) bool
- func (rm RoleMap) Each(fn func(Type) bool) bool
- func (rm RoleMap) Has(t Type) bool
- func (rm RoleMap) HasM(m dogma.Message) bool
- func (rm RoleMap) Remove(t Type) bool
- func (rm RoleMap) RemoveM(m dogma.Message) bool
- type Type
- type TypeContainer
- type TypeSet
Constants ¶
This section is empty.
Variables ¶
var Directions = []Direction{ InboundDirection, OutboundDirection, }
Directions is a slice of the valid message direcations.
var Roles = []Role{ CommandRole, EventRole, TimeoutRole, }
Roles is a slice of the valid message roles.
Functions ¶
func Description ¶ added in v0.7.0
Description returns a string representation of m.
If m implements Describer, it returns m.MessageDescription(). 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 Describer ¶ added in v0.7.0
type Describer interface {
// MessageDescription returns a human-readable description of the message.
//
// Engines may include the message description in logs, error messages, etc.
//
// As a general rule, the description should be worded such that it
// describes the behavior of the message to a non-technical person who is
// familiar with the business domain.
MessageDescription() string
}
Describer 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 Direction ¶
type Direction string
Direction is an enumeration of the "direction" a message is flowing, relative to a handler.
func (Direction) MustValidate ¶
func (d Direction) MustValidate()
MustValidate panics 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.
func (Role) Marker ¶
Marker returns a character that identifies the message role when displaying message types.
func (Role) MustValidate ¶
func (r Role) MustValidate()
MustValidate panics if r is not a valid message role.
type RoleMap ¶ added in v0.3.0
RoleMap is a map of message type to role. It implements the TypeContainer interface.
func (RoleMap) Add ¶ added in v0.3.0
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
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) Each ¶ added in v0.7.0
Each invokes fn once for each type in the container.
Iteration stops when fn returns false or once fn has been invoked for all types in the container.
It returns true if fn returned true for all types.
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 FromReflectType ¶ added in v0.7.0
FromReflectType returns the message type for the Go type reprsented by rt.
If rt does not implement dogma.Message then mt is nil, and ok is false.
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
// Each invokes fn once for each type in the container.
//
// Iteration stops when fn returns false or once fn has been invoked for all
// types in the container.
//
// It returns true if fn returned true for all types.
Each(fn func(Type) bool) 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 ¶
NewTypeSet returns a TypeSet containing the given types.
func (TypeSet) Add ¶
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 ¶
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) Each ¶ added in v0.7.0
Each invokes fn once for each type in the container.
Iteration stops when fn returns false or once fn has been invoked for all types in the container.
It returns true if fn returned true for all types.