core

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2021 License: MIT Imports: 4 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCausationID

func GetCausationID(ctx context.Context) string

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

func GetCorrelationID(ctx context.Context) string

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

func GetRequestID(ctx context.Context) string

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

func SerializeCommand(v Command) ([]byte, error)

SerializeCommand serializes commands with a registered marshaller

func SerializeEvent

func SerializeEvent(v Event) ([]byte, error)

SerializeEvent serializes events with a registered marshaller

func SerializeReply

func SerializeReply(v Reply) ([]byte, error)

SerializeReply serializes replies with a registered marshaller

func SerializeSagaData

func SerializeSagaData(v SagaData) ([]byte, error)

SerializeSagaData serializes saga data with a registered marshaller

func SerializeSnapshot

func SerializeSnapshot(v Snapshot) ([]byte, error)

SerializeSnapshot serializes snapshots with a registered marshaller

func SetRequestContext

func SetRequestContext(ctx context.Context, requestID, correlationID, causationID string) context.Context

SetRequestContext sets the Request, Correlation, and Causation IDs on the context

Correlation and Causation IDs will use the RequestID if blank ID values are provided

Types

type Command

type Command interface {
	CommandName() string
}

Command interface

func DeserializeCommand

func DeserializeCommand(commandName string, data []byte) (Command, error)

DeserializeCommand deserializes the command data using a registered marshaller returning a *Command

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 Event

type Event interface {
	EventName() string
}

Event interface

func DeserializeEvent

func DeserializeEvent(eventName string, data []byte) (Event, error)

DeserializeEvent deserializes the event data using a registered marshaller returning an *Event

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
})

type Reply

type Reply interface {
	ReplyName() string
}

Reply interface

func DeserializeReply

func DeserializeReply(replyName string, data []byte) (Reply, error)

DeserializeReply deserializes the reply data using a registered marshaller returning a *Reply

type SagaData

type SagaData interface {
	SagaDataName() string
}

SagaData interface

func DeserializeSagaData

func DeserializeSagaData(sagaDataName string, data []byte) (SagaData, error)

DeserializeSagaData deserializes the saga data data using a registered marshaller returning a *SagaData

type Snapshot

type Snapshot interface {
	SnapshotName() string
}

Snapshot interface

func DeserializeSnapshot

func DeserializeSnapshot(snapshotName string, data []byte) (Snapshot, error)

DeserializeSnapshot deserializes the snapshot data using a registered marshaller returning a *Snapshot

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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