transaction

package
v4.14.1 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoStore = errors.New("result store not found within batch context")

ErrNoStore is an error returned by components attempting to write a message batch to a ResultStore but are unable to locate the store within the batch context.

Functions

func AddResultStore

func AddResultStore(msg message.Batch, store ResultStore)

AddResultStore sets a result store within the context of the provided message that allows a roundtrip.Writer or any other component to propagate a resulting message back to the origin.

func SetAsResponse

func SetAsResponse(msg message.Batch) error

SetAsResponse takes a mutated message and stores it as a response message, this action fails if the message does not contain a valid ResultStore within its context.

Types

type ResultStore

type ResultStore interface {
	// Add a message to the store. The message will be deep copied and have its
	// context wiped before storing, and is therefore safe to add even when
	// ownership of the message is about to be yielded.
	Add(msg message.Batch)

	// Get the stored slice of messages.
	Get() []message.Batch

	// Clear any currently stored messages.
	Clear()
}

ResultStore is a type designed to be propagated along with a message as a way for an output destination to store the final version of the message payload as it saw it.

It is intended that this structure is placed within a message via an attached context, usually under the key 'result_store'.

func NewResultStore

func NewResultStore() ResultStore

NewResultStore returns an implementation of ResultStore.

type ResultStoreKeyType

type ResultStoreKeyType int

ResultStoreKeyType is the recommended type of a context key for adding ResultStores to a message context.

const ResultStoreKey ResultStoreKeyType = iota

ResultStoreKey is the recommended key value for adding ResultStores to a message context.

type Tracked

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

Tracked is a transaction type that adds identifying tags to messages such that an error returned resulting from multiple transaction messages can be reduced.

func NewTracked

func NewTracked(msg message.Batch, ackFn func(context.Context, error) error) *Tracked

NewTracked creates a transaction from a message batch and a response channel. The message is tagged with an identifier for the transaction, and if an error is returned from a downstream component that merged messages from other transactions the tag can be used in order to determine whether the message owned by this transaction succeeded.

func (*Tracked) Ack

func (t *Tracked) Ack(ctx context.Context, err error) error

Ack provides a response to the upstream service from an error.

func (*Tracked) Message

func (t *Tracked) Message() message.Batch

Message returns the message owned by this transaction.

Jump to

Keyboard shortcuts

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