event

package
v0.0.0-...-05ee0c8 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2021 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package event contains utilities for interacting with various event-stream providers. Including the ability to write and read from event-streaming sources.

Index

Constants

This section is empty.

Variables

View Source
var Ignore = errors.New("ignore")

Ignore is a sentinel error used to indicate that a read event has been a noop, this allows us to cancel traces and increment certain metrics. nolint: revive,stylecheck

Functions

This section is empty.

Types

type Event

type Event struct {
	ID        string
	Key       string
	Timestamp time.Time
	AppliesAt time.Time
	Payload   proto.Message
}

The Event type describes something that has happened at a particular point in time.

func New

func New(payload proto.Message, opts ...Option) Event

New returns a new Event instance that contains the provided payload. A unique identifier is generated and timestamps are set to now.

type Handler

type Handler func(ctx context.Context, evt Event) error

The Handler type is a function that processes an inbound event.

type Option

type Option func(e *Event)

The Option type is a function that can modify an event value.

func WithAppliesAt

func WithAppliesAt(appliesAt time.Time) Option

WithAppliesAt returns an Option that can be provided to New to set the Event.AppliesAt field.

func WithKey

func WithKey(key string) Option

WithKey returns an Option that can be provided to New to set the Event.Key field.

type Reader

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

The Reader type is used to handle inbound events from a single topic.

func NewReader

func NewReader(ctx context.Context, urlStr string) (*Reader, error)

NewReader creates a new instance of the Reader type that will read events from the configured event stream provider identified using the given URL.

func (*Reader) Close

func (r *Reader) Close() error

Close the connection to the event stream.

func (*Reader) Read

func (r *Reader) Read(ctx context.Context, fn Handler) error

Read events from the stream, invoking fn for each inbound event. This method will block until fn returns an error when messages are not nackable or the provided context is cancelled.

type Writer

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

The Writer type is used to write events to a single topic.

func NewWriter

func NewWriter(ctx context.Context, urlStr string) (*Writer, error)

NewWriter creates a new instance of the Writer type that will write events to the configured event stream provider identified using the given URL.

func (*Writer) Close

func (w *Writer) Close() error

Close the connection to the event stream.

func (*Writer) Write

func (w *Writer) Write(ctx context.Context, evt Event) error

Write an event to the stream.

Jump to

Keyboard shortcuts

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