saga

package module
v0.0.0-...-28b0f05 Latest Latest
Warning

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

Go to latest
Published: May 30, 2021 License: MIT Imports: 6 Imported by: 0

README

saga

The Saga implemenation in Golang and Kafka, for distributed transactions.

Upcoming:

  • hotreload configs using viper
  • make commands - everything command containerised
  • dependency injection using wire
  • example test
  • separate repo using saga
  • hotreload Rest APIs using air

Documentation

Overview

Example (SagaTransaction)
// storage := kafka.NewKafka(version, brokerAddresses, options...)
// saga := NewSaga()
// saga.AddSubTx("debit", DebitAccount, CompensateDebitAccount)
// saga.AddSubTx("credit, "CreditAccount, CompensateCreditAccount)
// tx := NewTx(ctx, saga, storage, logger, txID)
// tx.Start()
// tx.ExecuteAndGetResults("initialize transfer", from, to)
// tx.Execute("debit", account, amount) -> if err do -> tx.Abort
// tx.Execute("credit", credit, amount) -> if err do -> tx.Abort
// tx.End()
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ParamRegister

type ParamRegister interface {
	Add(funcObj interface{}) error
	GetRegisteredTypeName(t reflect.Type) (typ string, err error)
	GetRegisteredType(typ string) (t reflect.Type, err error)
}

ParamRegister contains methods to add sub-transaction parameters metadata

type Saga

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

Saga helps SubTransaction execution and rollback

func New

func New() *Saga

New creates and returns a new Saga instance

func NewWithLogger

func NewWithLogger(l trace.Logger) *Saga

NewWithLogger creates and returns a new Saga instance with given Logger

func (*Saga) AddSubTx

func (s *Saga) AddSubTx(ID string, action interface{}, compensate interface{}) error

AddSubTx registers the action and compensate methods for a SubTx that'll be identified with the SubTxID. While Transaction execution, the SubTxID is used to identify the SubTx and execute it's action in success flow or compensate if Tx is being rollback.

func (*Saga) GetSubTxDef

func (s *Saga) GetSubTxDef(subTxID string) (subtx.Definition, error)

func (*Saga) MarshallArgs

func (s *Saga) MarshallArgs(args []interface{}) ([]log.ArgData, error)

func (*Saga) UnmarshallArgs

func (s *Saga) UnmarshallArgs(argData []log.ArgData) ([]reflect.Value, error)

type SubTxDefinitions

type SubTxDefinitions interface {
	Add(subTxID string, action interface{}, compensate interface{}) error
	Get(subTxID string) (subtx.Definition, error)
}

SubTxDefinitions contains methods to add sub-transaction definitions

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
storage

Jump to

Keyboard shortcuts

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