saga

package
v0.0.0-...-e360745 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package saga implements saga orchestration logic.

Index

Constants

View Source
const (
	CommandStart    = "start"
	QueueName       = "responses"
	StatusStarted   = "started"
	StatusError     = "error"
	StatusWorkDone  = "done"
	StatusCompleted = "completed"
)

Variables

View Source
var (
	ErrEndOfWorkflow   = fmt.Errorf("end of workflow")
	ErrServiceNotFound = fmt.Errorf("service not found")
)
View Source
var SampleWorkflow = []Service{
	{
		"service1", "commands1", nil,
	},
	{
		"service2", "commands2", nil,
	},
	{
		"service3", "commands3", nil,
	},
}

Functions

This section is empty.

Types

type Saga

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

Saga contains the database for storing URLs.

func New

func New(workflow Workflow, storage Storer) Saga

New constructs a new Saga.

func (Saga) ProcessMessage

func (s Saga) ProcessMessage(ctx context.Context, inp any) error

ProcessMessage receives a message with a response from a service and decides which service has to be called next according to the saga workflow.

func (Saga) Start

func (s Saga) Start(ctx context.Context, sagaID uuid.UUID) error

Start starts a new saga with a given ID. The method can be called by HTTP handler.

type Sender

type Sender interface {
	Send(any) error
}

Sender interface abstracts sending a message to queue.

type Service

type Service struct {
	Name   string
	Topic  string
	Sender Sender
}

Service type has data for a service which is orchestrated by a saga.

type Storer

type Storer interface {
	InsertSaga(context.Context, uuid.UUID, string, string) error
	UpdateStatus(context.Context, uuid.UUID, string) error
	UpdateService(context.Context, uuid.UUID, string, string) error
}

Storer interface abstracts data access operations for persisting a saga.

type Workflow

type Workflow struct {
	Services []Service
}

Workflow represents a saga workflow with a list of services in order of their sequential execution.

func NewWorkflowWithSQS

func NewWorkflowWithSQS(services []Service, awsSQS *sqs.SQS) (Workflow, error)

NewWorkflowWithSQS initializes a new workflow with a SQS queues for each service.

Jump to

Keyboard shortcuts

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