Documentation
¶
Index ¶
- Constants
- func WithSagaInfo(instance *Instance) msg.MessageOption
- type Command
- type CommandDispatcher
- type CommandDispatcherOption
- type CommandHandlerFunc
- type Definition
- type Instance
- type InstanceStore
- type LifecycleHook
- type LocalStep
- type Orchestrator
- type OrchestratorOption
- type RemoteStep
- func (s RemoteStep) Action(fn func(context.Context, core.SagaData) msg.DomainCommand, ...) RemoteStep
- func (s RemoteStep) Compensation(fn func(context.Context, core.SagaData) msg.DomainCommand, ...) RemoteStep
- func (s RemoteStep) HandleActionReply(reply core.Reply, ...) RemoteStep
- func (s RemoteStep) HandleCompensationReply(reply core.Reply, ...) RemoteStep
- type RemoteStepActionOption
- type Step
Constants ¶
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 ¶
func (d *CommandDispatcher) Handle(cmd core.Command, handler CommandHandlerFunc) *CommandDispatcher
Handle adds a new Command that will be handled by handler
func (*CommandDispatcher) ReceiveMessage ¶
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 ¶
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 ¶
Compensating returns whether or not the instance is compensating (rolling back)
func (*Instance) CurrentStep ¶
CurrentStep returns the step currently being processed
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 ¶
NewLocalStep constructor for LocalStep
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 ¶
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
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 (RemoteStep) Action ¶
func (s RemoteStep) Action(fn func(context.Context, core.SagaData) msg.DomainCommand, options ...RemoteStepActionOption) RemoteStep
Action adds a domain command constructor that will be called while the definition is advancing
func (RemoteStep) Compensation ¶
func (s RemoteStep) Compensation(fn func(context.Context, core.SagaData) msg.DomainCommand, options ...RemoteStepActionOption) RemoteStep
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