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 ¶
- type ParamRegister
- type Saga
- func (s *Saga) AddSubTx(ID string, action interface{}, compensate interface{}) error
- func (s *Saga) GetSubTxDef(subTxID string) (subtx.Definition, error)
- func (s *Saga) MarshallArgs(args []interface{}) ([]log.ArgData, error)
- func (s *Saga) UnmarshallArgs(argData []log.ArgData) ([]reflect.Value, error)
- type SubTxDefinitions
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 NewWithLogger ¶
NewWithLogger creates and returns a new Saga instance with given Logger
func (*Saga) AddSubTx ¶
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)
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
Click to show internal directories.
Click to hide internal directories.