correlation

package
v0.0.0-...-fff96b5 Latest Latest
Warning

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

Go to latest
Published: May 10, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package correlation contains extensions for eventually key components to support correlated events for tracing and debugging purposes.

You can read more about events correlation here: https://blog.arkency.com/correlation-id-and-causation-id-in-evented-systems/

Index

Constants

View Source
const (
	EventIDKey       = "Event-Id"
	CorrelationIDKey = "Correlation-Id"
	CausationIDKey   = "Causation-Id"
)

Metadata keys used by the package.

Variables

This section is empty.

Functions

func CausationIDContext

func CausationIDContext(ctx context.Context) (string, bool)

CausationIDContext returns the Causation id from the context, if it has been set using WithCausationID modifier.

func IDContext

func IDContext(ctx context.Context) (string, bool)

IDContext returns the Correlation id from the context, if it has been set using WithCorrelationID modifier.

func WithCausationID

func WithCausationID(ctx context.Context, id string) context.Context

WithCausationID adds the specified causation id in the context, which will be used by the other extension components exposed by this package.

func WithCorrelationID

func WithCorrelationID(ctx context.Context, id string) context.Context

WithCorrelationID adds the specified correlation id in the context, which will be used by the other extension components exposed by this package.

Types

type EventStoreWrapper

type EventStoreWrapper struct {
	eventstore.Store
	// contains filtered or unexported fields
}

EventStoreWrapper is an extension component that adds support for Correlation, Causation and Event id recording in all Events committed to the underlying EventStore.

Check WrapEventStore for more information.

func WrapEventStore

func WrapEventStore(es eventstore.Store, generator Generator) EventStoreWrapper

WrapEventStore wraps the provided eventstore.Store instance with an EventStoreWrapper extension.

EventStoreWrapper will add an Event id for each Event committed through this instance, using the specified Generator interface.

Also, it will add Correlation and Causation ids in the committed Events Metadata, if present in the context. You can check correlation.WithCorrelationID and correlation.WithCausationID functions, or correlation.ProjectionWrapper for more info.

func (EventStoreWrapper) Append

func (esw EventStoreWrapper) Append(
	ctx context.Context,
	id eventstore.StreamID,
	expected eventstore.VersionCheck,
	events ...eventually.Event,
) (int64, error)

Append extracts or creates an Event, Correlation and Causation id from the context, applies it to all the Events provided and forwards it to the wrapped Event Store.

type Generator

type Generator func() string

Generator is a string identifier generator.

type Message

type Message eventually.Message

Message extends an eventually.Message instance to fetch Correlation and Causation ids from the Message Metadata.

func (Message) CausationID

func (msg Message) CausationID() (string, bool)

CausationID returns the Causation id from the Message Metadata, if found.

func (Message) CorrelationID

func (msg Message) CorrelationID() (string, bool)

CorrelationID returns the Correlation id from the Message Metadata, if found.

func (Message) EventID

func (msg Message) EventID() (string, bool)

EventID returns the Message identifier from the Message Metadata, if found.

type ProjectionWrapper

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

ProjectionWrapper is an extension component that adds Correlation and Causation ids to the context of the underlying projection.Applier instance, if found in the Message received in Apply.

Use WrapProjection to create a new instance.

func WrapProjection

func WrapProjection(applier projection.Applier) ProjectionWrapper

WrapProjection wraps the specified projection.Applier instance with a ProjectionWrapper extension component.

func (ProjectionWrapper) Apply

func (pw ProjectionWrapper) Apply(ctx context.Context, event eventstore.Event) error

Apply applies the provided Event to the wrapped projection.Applier, using an augmented context containing Correlation and Causation ids in the Event Metadata, if any.

Jump to

Keyboard shortcuts

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