outbox

package module
v0.0.0-...-1e1f105 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

README

eh-outbox: An implementation of standard outbox pattern.

eh-outbox is the experimental driver of standard message outbox and message relay pattern which is useful to publish the domain events to external service as well as to preapare the different read views. It will help to decouple the write and read side, so even if readside service/db is down, still the write side will be operational.

Note: It is experimental driver and eventually will be merge to eventhorizon(https://github.com/looplab/eventhorizon) once it is stable enough.

Design: alt text

Documentation

Index

Constants

View Source
const (
	Stopped = 0
	Paused  = 1
	Running = 2
)

Possible worker states.

Variables

View Source
var (
	// ErrInvalidEventData error returned when a events data is invalid
	ErrInvalidEventData = errors.New("Invalid Event data")
	// ErrConvertToExternalEvent error returned when converter fails to convert internal event to external event
	ErrConvertToExternalEvent = errors.New("Failed !! to convert to external event")
	// ErrSkipThisEvent error returned when custom converter skip this event, while pulishing to read side.
	ErrSkipThisEvent = errors.New("Info !! event skipped by converter implementation")
	// ErrProjectorNotInitialized error returned when a projector object not been initialized properly.
	ErrProjectorNotInitialized = errors.New("Error !! projector not initiallized")
)

Functions

func AssignProjectorID

func AssignProjectorID(name string, offsetRepo *mongodb.Repo) int32

AssignProjectorID will assign a bit position to the concrete projector at the time of projector registration

func Reset

func Reset(ctx context.Context, repoOutbox *mongodb.Repo, repoOffset *mongodb.Repo) error

Reset operation should be atomic and should run in isolation in respect to other post call to eventhorizon

Types

type DefaultConverter

type DefaultConverter struct {
}

DefaultConverter to publish the internal event as it is

func (*DefaultConverter) ConvertToExternalEvent

func (d *DefaultConverter) ConvertToExternalEvent(ctx context.Context, event eh.Event) (interface{}, error)

ConvertToExternalEvent for defautlt converter

type EventOutbox

type EventOutbox struct {
	InProg    int32        `json:"inProg"         bson:"inProg"`
	Done      int32        `json:"done"           bson:"done"`
	EventType eh.EventType `json:"event_type"     bson:"event_type"`
	Data      interface{}  `json:"data"           bson:"data"`
	Timestamp time.Time    `json:"timestamp"      bson:"timestamp"`
}

EventOutbox is helper to write the events to outbox

func (*EventOutbox) SaveToOutbox

func (eventOutbox *EventOutbox) SaveToOutbox(ctx context.Context, repo *mongodb.Repo,
	id interface{}, eventType eh.EventType) error

SaveToOutbox save events to outbox.

type HoldOutboxEvent

type HoldOutboxEvent struct {
	ID        bson.ObjectId `json:"_id"            bson:"_id,omitempty"`
	InProg    int32         `json:"inProg"         bson:"inProg"`
	Done      int32         `json:"done"           bson:"done"`
	EventType eh.EventType  `json:"event_type"     bson:"event_type"`
	Data      interface{}   `json:"data"           bson:"data"`
	Timestamp time.Time     `json:"timestamp"      bson:"timestamp"`
}

HoldOutboxEvent is helper to read scan events from outbox.

func (*HoldOutboxEvent) FindAndModify

func (holdEvent *HoldOutboxEvent) FindAndModify(ctx context.Context, repo *mongodb.Repo, filter bson.M, change mgo.Change) error

FindAndModify to read a event from outbox follwing filter and change rules. Need ckt breaker to save db call incase there is no more event to be scan by projector

type IConverter

type IConverter interface {
	ConvertToExternalEvent(ctx context.Context, event eh.Event) (interface{}, error)
}

IConverter is to inject logic to convert internal to external event

type IOutbox

type IOutbox interface {
	FindAndModify(ctx context.Context, repo *mongodb.Repo, filter bson.M, change mgo.Change) error
}

IOutbox interface to scan events from outbox.

type IProjector

type IProjector interface {
	Name() string
	Bit() int32
	AssignProjectorID(offsetRepo *mongodb.Repo)
	OutboxRepo() *mongodb.Repo
	OffsetRepo() *mongodb.Repo
	Converter() IConverter
	WriteToReadside(ctx context.Context, key string, data interface{}) error
}

IProjector is the interface for all the projector

type ReadProjectorGroup

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

ReadProjectorGroup is collection of iWorker

func GetReadProjectorGroup

func GetReadProjectorGroup() *ReadProjectorGroup

GetReadProjectorGroup get the singleton object of ReadProjectorGroup

func (*ReadProjectorGroup) RegisterProjector

func (rpg *ReadProjectorGroup) RegisterProjector(p IProjector)

RegisterProjector to register a new readside projector

func (*ReadProjectorGroup) Start

func (rpg *ReadProjectorGroup) Start()

Start all the projector worker

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳