Documentation ¶
Index ¶
- func GetCausationID(ctx context.Context) string
- func GetCorrelationID(ctx context.Context) string
- func GetRequestID(ctx context.Context) string
- func RegisterCommands(commands ...Command)
- func RegisterDefaultMarshaller(marshaller Marshaller)
- func RegisterEvents(events ...Event)
- func RegisterMarshaller(marshaller Marshaller, affinityFn func(interface{}) bool)
- func RegisterReplies(replies ...Reply)
- func RegisterSagaData(sagaDatas ...SagaData)
- func RegisterSnapshots(snapshots ...Snapshot)
- func SerializeCommand(v Command) ([]byte, error)
- func SerializeEvent(v Event) ([]byte, error)
- func SerializeReply(v Reply) ([]byte, error)
- func SerializeSagaData(v SagaData) ([]byte, error)
- func SerializeSnapshot(v Snapshot) ([]byte, error)
- func SetRequestContext(ctx context.Context, requestID, correlationID, causationID string) context.Context
- type Command
- type Entity
- type EntityBase
- type Event
- type Marshaller
- type Reply
- type SagaData
- type Snapshot
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetCausationID ¶
GetCausationID returns the CausationID from the context or a blank if not set
In a long line of events, commands and messages this ID will match the previous RequestID
func GetCorrelationID ¶
GetCorrelationID returns the CorrelationID from the context or a blank if not set
In a long line of events, commands and messages this ID will match the original RequestID
func GetRequestID ¶
GetRequestID returns the RequestID from the context or a blank if not set
func RegisterCommands ¶
func RegisterCommands(commands ...Command)
RegisterCommands registers one or more commands with a registered marshaller
Register commands using any form desired "&MyCommand{}", "MyCommand{}", "(*MyCommand)(nil)"
Commands must be registered after first registering a marshaller you wish to use
func RegisterDefaultMarshaller ¶
func RegisterDefaultMarshaller(marshaller Marshaller)
RegisterDefaultMarshaller registers a marshaller to be used when no other marshaller should be used
func RegisterEvents ¶
func RegisterEvents(events ...Event)
RegisterEvents registers one or more events with a registered marshaller
Register events using any form desired "&MyEvent{}", "MyEvent{}", "(*MyEvent)(nil)"
Events must be registered after first registering a marshaller you wish to use
func RegisterMarshaller ¶
func RegisterMarshaller(marshaller Marshaller, affinityFn func(interface{}) bool)
RegisterMarshaller allows applications to register a new optimized marshaller for specific types or situations
func RegisterReplies ¶
func RegisterReplies(replies ...Reply)
RegisterReplies registers one or more replies with a registered marshaller
Register replies using any form desired "&MyReply{}", "MyReply{}", "(*MyReply)(nil)"
Replies must be registered after first registering a marshaller you wish to use
func RegisterSagaData ¶
func RegisterSagaData(sagaDatas ...SagaData)
RegisterSagaData registers one or more saga data with a registered marshaller
Register saga data using any form desired "&MySagaData{}", "MySagaData{}", "(*MySagaData)(nil)"
SagaData must be registered after first registering a marshaller you wish to use
func RegisterSnapshots ¶
func RegisterSnapshots(snapshots ...Snapshot)
RegisterSnapshots registers one or more snapshots with a registered marshaller
Register snapshots using any form desired "&MySnapshot{}", "MySnapshot{}", "(*MySnapshot)(nil)"
Snapshots must be registered after first registering a marshaller you wish to use
func SerializeCommand ¶
SerializeCommand serializes commands with a registered marshaller
func SerializeEvent ¶
SerializeEvent serializes events with a registered marshaller
func SerializeReply ¶
SerializeReply serializes replies with a registered marshaller
func SerializeSagaData ¶
SerializeSagaData serializes saga data with a registered marshaller
func SerializeSnapshot ¶
SerializeSnapshot serializes snapshots with a registered marshaller
Types ¶
type Entity ¶
type Entity interface { ID() string EntityName() string Events() []Event AddEvent(events ...Event) ClearEvents() }
Entity have identity and change tracking in the form of events
type EntityBase ¶
type EntityBase struct {
// contains filtered or unexported fields
}
EntityBase provides entities a base to build on
func (*EntityBase) AddEvent ¶
func (e *EntityBase) AddEvent(events ...Event)
AddEvent adds a tracked change to the Entity
func (*EntityBase) ClearEvents ¶
func (e *EntityBase) ClearEvents()
ClearEvents resets the tracked change list
func (*EntityBase) Events ¶
func (e *EntityBase) Events() []Event
Events returns all tracked changes made to the Entity as Events
type Marshaller ¶
type Marshaller interface { Marshal(interface{}) ([]byte, error) Unmarshal([]byte, interface{}) error GetType(typeName string) reflect.Type RegisterType(typeName string, v reflect.Type) }
Marshaller provides marshaling functions and type tracking capabilities
This is how the library avoids requiring boilerplate written to convert each data type to and from a marshalled form.
An example marshaller that uses gogoproto with "gogoslick_out" code generation. Adding a protobuf based Marshaller will result in significant speed improvements at the expense of having to maintain generated code.
// Define a marshaller type MyProtoMarshaller struct{} func (MyProtoMarshaller) Marshal(v interface{}) ([]byte, error) { return proto.Marshal(v.(proto.Message))} func (MyProtoMarshaller) Unmarshal(data []byte, v interface{}) error { return proto.Unmarshal(data, v.(proto.Message))} func (MyProtoMarshaller) GetType(typeName string) reflect.Type { t := proto.MessageType(typeName) if t != nil { return t.Elem() } return nil } func (ProtoMarshaller) RegisterType(string, reflect.Type) {} // Register your marshaller and a function to test for the types it should be given to handle core.RegisterMarshaller(MyProtoMarshaller{}, func(i interface{}) bool { _, ok := i.(proto.Message) return ok })