sec

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2023 License: BSD-3-Clause Imports: 9 Imported by: 0

README

The SEC package

refers to the implementation of a "Saga Execution Coordinator" (SEC) in the context of an event-driven architecture. This package is a key component that enables the management of distributed transactions through sagas, which are sequences of steps that define the actions and trade-offs required in a distributed system. Here is a summary of the components and functions of the SEC package:

Orchestrator:

Handles incoming responses to determine which saga step to execute next. It has two modes of operation: manual start or reaction to incoming responses.

Saga Definition:

Contains the metadata and sequence of steps of the saga, establishing how the saga should operate.

Steps:

The steps contain the logic of the saga. They generate command messages sent to participants and can modify the data associated with the saga.

The SEC package centralizes the orchestration logic of a saga's actions in one place, facilitating the management of complex and distributed processes. This is essential in systems where coordination between multiple components is required and where actions must be compensated in case of errors or failures. Using an SEC helps maintain consistency and integrity of operations throughout the application, especially in microservices architectures or distributed systems.

Documentation

Index

Constants

View Source
const (
	SagaCommandIDHdr   = async.CommandHdrPrefix + "SAGA_ID"
	SagaCommandNameHdr = async.CommandHdrPrefix + "SAGA_NAME"

	SagaReplyIDHdr   = async.ReplyHdrPrefix + "SAGA_ID"
	SagaReplyNameHdr = async.ReplyHdrPrefix + "SAGA_NAME"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Orchestrator

type Orchestrator[T any] interface {
	Start(ctx context.Context, id string, data T) error
	ReplyTopic() string
	HandleReply(ctx context.Context, reply ddd.Reply) error
}

func NewOrchestrator

func NewOrchestrator[T any](saga Saga[T], repo SagaRepository[T], publisher async.CommandPublisher) Orchestrator[T]

type Saga

type Saga[T any] interface {
	AddStep() SagaStep[T]
	Name() string
	ReplyTopic() string
	// contains filtered or unexported methods
}

func NewSaga

func NewSaga[T any](name, replyTopic string) Saga[T]

type SagaContext

type SagaContext[T any] struct {
	ID           string
	Data         T
	Step         int
	Done         bool
	Compensating bool
}

type SagaRepository

type SagaRepository[T any] struct {
	// contains filtered or unexported fields
}

func NewSagaRepository

func NewSagaRepository[T any](reg registry.Registry, store SagaStore) SagaRepository[T]

func (SagaRepository[T]) Load

func (r SagaRepository[T]) Load(ctx context.Context, sagaName, sagaID string) (*SagaContext[T], error)

func (SagaRepository[T]) Save

func (r SagaRepository[T]) Save(ctx context.Context, sagaName string, sagaCtx *SagaContext[T]) error

type SagaStep

type SagaStep[T any] interface {
	Action(fn StepActionFunc[T]) SagaStep[T]
	Compensation(fn StepActionFunc[T]) SagaStep[T]
	OnActionReply(replyName string, fn StepReplyHandlerFunc[T]) SagaStep[T]
	OnCompensationReply(replyName string, fn StepReplyHandlerFunc[T]) SagaStep[T]
	// contains filtered or unexported methods
}

type SagaStore

type SagaStore interface {
	Load(ctx context.Context, sagaName, sagaID string) (*SagaContext[[]byte], error)
	Save(ctx context.Context, sagaName string, sagaCtx *SagaContext[[]byte]) error
}

type StepActionFunc

type StepActionFunc[T any] func(ctx context.Context, data T) (string, ddd.Command, error)

type StepOption

type StepOption[T any] func(step *sagaStep[T])

func OnActionReply

func OnActionReply[T any](replyName string, fn StepReplyHandlerFunc[T]) StepOption[T]

func OnCompensationReply

func OnCompensationReply[T any](replyName string, fn StepReplyHandlerFunc[T]) StepOption[T]

func WithAction

func WithAction[T any](fn StepActionFunc[T]) StepOption[T]

func WithCompensation

func WithCompensation[T any](fn StepActionFunc[T]) StepOption[T]

type StepReplyHandlerFunc

type StepReplyHandlerFunc[T any] func(ctx context.Context, data T, reply ddd.Reply) error

Jump to

Keyboard shortcuts

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