event

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2021 License: MIT Imports: 22 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

This section is empty.

Functions

This section is empty.

Types

type Event

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

The Event type describes something that has happened at a particular point in time. It contains information on who sent it and when. Each event payload is a proto-encoded message.

func New added in v1.8.0

func New(msg proto.Message) Event

New returns a new Event instance that contains the provided proto.Message implementation. A unique identifier is generated, timestamps are set to now and the application name is taken from environment.ApplicationName.

type Handler

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

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

type MultiReader

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

The MultiReader type is used to handle inbound events from multiple topics across different event stream providers.

func NewMultiReader

func NewMultiReader(ctx context.Context, urls []string) (*MultiReader, error)

NewMultiReader creates a new instance of the MultiReader type that will read events from the configured event stream providers identified using the given URLs.

func (*MultiReader) Close

func (mr *MultiReader) Close() error

Close all event stream connections.

func (*MultiReader) Read

func (mr *MultiReader) 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 or the provided context is cancelled.

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 or the provided context is cancelled.

type Sender added in v1.8.0

type Sender struct {
	Application string
	Metadata    map[string]string
}

Sender contains details on who sent an Event.

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. If the provided context.Context contains tracing information, it is added to Event.Sender.Metadata so that tracing can occur across event readers/writers.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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