saga

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: 7 Imported by: 2

Documentation

Index

Constants

View Source
const (
	MessageCommandSagaID   = msg.MessageCommandPrefix + "SAGA_ID"
	MessageCommandSagaName = msg.MessageCommandPrefix + "SAGA_NAME"
	MessageCommandResource = msg.MessageCommandPrefix + "RESOURCE"

	MessageReplySagaID   = msg.MessageReplyPrefix + "SAGA_ID"
	MessageReplySagaName = msg.MessageReplyPrefix + "SAGA_NAME"
)

Saga message headers

Variables

This section is empty.

Functions

func WithSagaInfo

func WithSagaInfo(instance *Instance) msg.MessageOption

WithSagaInfo is an option to set additional Saga specific headers

Types

type Command

type Command interface {
	SagaID() string
	SagaName() string
	Command() core.Command
	Headers() msg.Headers
}

Command is a core.Command with message header information

type CommandDispatcher

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

CommandDispatcher is a MessageReceiver for Commands

func NewCommandDispatcher

func NewCommandDispatcher(publisher msg.ReplyMessagePublisher, options ...CommandDispatcherOption) *CommandDispatcher

NewCommandDispatcher constructs a new CommandDispatcher

func (*CommandDispatcher) Handle

Handle adds a new Command that will be handled by handler

func (*CommandDispatcher) ReceiveMessage

func (d *CommandDispatcher) ReceiveMessage(ctx context.Context, message msg.Message) error

ReceiveMessage implements MessageReceiver.ReceiveMessage

type CommandDispatcherOption

type CommandDispatcherOption func(consumer *CommandDispatcher)

CommandDispatcherOption options for CommandConsumers

func WithCommandDispatcherLogger

func WithCommandDispatcherLogger(logger log.Logger) CommandDispatcherOption

WithCommandDispatcherLogger is an option to set the log.Logger of the CommandDispatcher

type CommandHandlerFunc

type CommandHandlerFunc func(context.Context, Command) ([]msg.Reply, error)

CommandHandlerFunc function handlers for saga.Command

type Definition

type Definition interface {
	SagaName() string
	ReplyChannel() string
	Steps() []Step
	OnHook(hook LifecycleHook, instance *Instance)
}

Definition interface

type Instance

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

Instance is the container for saga data

func NewSagaInstance

func NewSagaInstance(sagaName, sagaID string, sagaData core.SagaData, currentStep int, endState, compensating bool) *Instance

NewSagaInstance constructor for *SagaInstances

func (*Instance) Compensating

func (i *Instance) Compensating() bool

Compensating returns whether or not the instance is compensating (rolling back)

func (*Instance) CurrentStep

func (i *Instance) CurrentStep() int

CurrentStep returns the step currently being processed

func (*Instance) EndState

func (i *Instance) EndState() bool

EndState returns whether or not all steps have completed

func (*Instance) SagaData

func (i *Instance) SagaData() core.SagaData

SagaData returns the instance saga data

func (*Instance) SagaID

func (i *Instance) SagaID() string

SagaID returns the instance saga id

func (*Instance) SagaName

func (i *Instance) SagaName() string

SagaName returns the instance saga name

type InstanceStore

type InstanceStore interface {
	Find(ctx context.Context, sagaName, sagaID string) (*Instance, error)
	Save(ctx context.Context, sagaInstance *Instance) error
	Update(ctx context.Context, sagaInstance *Instance) error
}

InstanceStore interface

type LifecycleHook

type LifecycleHook int

LifecycleHook type for hooking in custom code at specific stages of a saga

const (
	SagaStarting LifecycleHook = iota
	SagaCompleted
	SagaCompensated
)

Definition lifecycle hooks

type LocalStep

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

LocalStep is used to execute local saga business logic

func NewLocalStep

func NewLocalStep(action func(context.Context, core.SagaData) error) LocalStep

NewLocalStep constructor for LocalStep

func (LocalStep) Compensation

func (s LocalStep) Compensation(compensation func(context.Context, core.SagaData) error) LocalStep

Compensation sets the compensating action for this step

type Orchestrator

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

Orchestrator orchestrates local and distributed processes

func NewOrchestrator

func NewOrchestrator(definition Definition, store InstanceStore, publisher msg.CommandMessagePublisher, options ...OrchestratorOption) *Orchestrator

NewOrchestrator constructs a new Orchestrator

func (*Orchestrator) ReceiveMessage

func (o *Orchestrator) ReceiveMessage(ctx context.Context, message msg.Message) error

ReceiveMessage implements msg.MessageReceiver.ReceiveMessage

func (*Orchestrator) ReplyChannel

func (o *Orchestrator) ReplyChannel() string

ReplyChannel returns the channel replies are to be received from msg.Subscribers

func (*Orchestrator) Start

func (o *Orchestrator) Start(ctx context.Context, sagaData core.SagaData) (*Instance, error)

Start creates a new instance of the saga and begins execution

type OrchestratorOption

type OrchestratorOption func(o *Orchestrator)

OrchestratorOption options for Orchestrator

func WithOrchestratorLogger

func WithOrchestratorLogger(logger log.Logger) OrchestratorOption

WithOrchestratorLogger is an option to set the log.Logger of the Orchestrator

type RemoteStep

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

RemoteStep is used to execute distributed saga business logic

func NewRemoteStep

func NewRemoteStep() RemoteStep

NewRemoteStep constructor for RemoteStep

func (RemoteStep) Action

Action adds a domain command constructor that will be called while the definition is advancing

func (RemoteStep) Compensation

Compensation adds a domain command constructor that will be called while the definition is compensating

func (RemoteStep) HandleActionReply

func (s RemoteStep) HandleActionReply(reply core.Reply, handler func(context.Context, core.SagaData, core.Reply) error) RemoteStep

HandleActionReply adds additional handling for specific replies while advancing

SuccessReply and FailureReply do not require any special handling unless desired

func (RemoteStep) HandleCompensationReply

func (s RemoteStep) HandleCompensationReply(reply core.Reply, handler func(context.Context, core.SagaData, core.Reply) error) RemoteStep

HandleCompensationReply adds additional handling for specific replies while compensating

SuccessReply does not require any special handling unless desired

type RemoteStepActionOption

type RemoteStepActionOption func(action *remoteStepAction)

RemoteStepActionOption options for remoteStepAction

func WithRemoteStepPredicate

func WithRemoteStepPredicate(predicate func(context.Context, core.SagaData) bool) RemoteStepActionOption

WithRemoteStepPredicate sets a predicate function for the action

type Step

type Step interface {
	// contains filtered or unexported methods
}

Step interface for local, remote, ...other saga steps

Jump to

Keyboard shortcuts

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