direct

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package direct provides a saga mapping strategy that maps messages to saga instances by having the saga implement a method that returns the instance ID directly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mapper

type Mapper struct {
	Resolver Resolver
}

Mapper is an implementation of saga.Mapper that maps messages to saga instances using only information contained in the message.

func ByField

func ByField(f ...string) *Mapper

ByField returns a mapper that maps messages to instances using a set of fields within the message.

All fields must be strings. If any of the fields are empty, the message is not routed to any instance.

func WithPrefix

func WithPrefix(prefix string, m *Mapper) *Mapper

WithPrefix returns a mapper that wraps around m and adds a prefix string to the instance ID returned by m's Resolver.

If m's Resolver does not return a valid instance ID, no prefix is added.

func (*Mapper) DeleteMapping

func (m *Mapper) DeleteMapping(
	context.Context,
	saga.Saga,
	persistence.Tx,
	saga.Instance,
) error

DeleteMapping notifies the mapper that an instance has been completed, allowing it to remove it's mapping information, if necessary.

func (*Mapper) MapMessageToInstance

func (m *Mapper) MapMessageToInstance(
	_ context.Context,
	_ saga.Saga,
	_ persistence.Tx,
	env ax.Envelope,
) (saga.InstanceID, bool, error)

MapMessageToInstance returns the ID of the saga instance that is the target of the given message.

It returns false if the message should be ignored.

func (*Mapper) UpdateMapping

func (m *Mapper) UpdateMapping(
	context.Context,
	saga.Saga,
	persistence.Tx,
	saga.Instance,
) error

UpdateMapping notifies the mapper that an instance has been modified, allowing it to update it's mapping information, if necessary.

type Resolver

type Resolver interface {
	// InstanceIDForMessage returns the ID of the saga instance to which the
	// given message is routed, if any.
	//
	// If ok is false the message is ignored; otherwise, the message is routed
	// to the saga instance with the returned ID.
	InstanceIDForMessage(env ax.Envelope) (saga.InstanceID, bool)
}

Resolver is an interface that provides the application-defined logic for mapping a message to its target saga instance.

Jump to

Keyboard shortcuts

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