pubsub

package
v0.0.0-...-f1b319b Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2023 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package pubsub is an abstraction of any publisher-subscriber mechanism.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorHandler

type ErrorHandler func(context.Context, error, *Event)

ErrorHandler should handle the given error and deal with the optional event if necessary.

type Event

type Event struct {
	// ID holds the event unique ID, to be used for idempotency purposes.
	ID ID `json:"id"`

	// Name indicates the event name or type.
	Name Name `json:"name"`

	// Meta encapsulates contextual information.
	Meta Meta `json:"meta"`

	// Payload holds the actual event message.
	Payload []byte `json:"payload"`
}

Event defines the event envelope.

func NewEvent

func NewEvent(ctx context.Context, name Name, msg []byte) Event

NewEvent creates an event of the specified name that uses contextual information and the given message.

type Handler

type Handler func(context.Context, Event) error

Handler handles the given event.

type ID

type ID string

ID indicates the event identifier.

type Meta

type Meta struct {
	// CreatedAtUTC indicates the UTC time when the event was created.
	CreatedAtUTC time.Time `json:"created_at_utc"`

	// CorrelationID holds the request correlation ID.
	CorrelationID string `json:"correlation_id"`

	// Attempts indicates how many times the event has been handled.
	Attempts int `json:"attempts"`

	// IsDryRun indicates whether the execution is a dry run.
	IsDryRun bool `json:"is_dry_run"`
}

Meta encapsulates execution information.

type Name

type Name string

Name indicates the event type.

type Publisher

type Publisher interface {
	// Emit publishes the given events to the stream.
	Emit(context.Context, ...Event) error

	// Close should close any underlying connection.
	Close() error
}

Publisher defines the capabilities of any publisher.

type Subscriber

type Subscriber interface {
	// Consume takes a single event from the stream and processes it using the
	// given handler. The event will be sent to the error handler in case of
	// failure.
	Consume(context.Context, Handler, ErrorHandler)

	// Close should close any underlying connection.
	Close() error
}

Subscriber defines the capabilities of any subscriber.

Directories

Path Synopsis
Package memory provides an in-memory pubsub mechanism.
Package memory provides an in-memory pubsub mechanism.
Package pubsubtest simplifies the interaction with the pubsub package when running tests.
Package pubsubtest simplifies the interaction with the pubsub package when running tests.
Package redis provides a way to interact with redis streams.
Package redis provides a way to interact with redis streams.

Jump to

Keyboard shortcuts

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