event

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2020 License: MIT Imports: 12 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 {
	Topic   string // Set internally when reading, not used when writing.
	Payload []byte
}

The Event type represents an event that can be written or read from the stream. It just contains a slice of bytes that the user must marshal into whatever types they desire. It does not assume serialization format, so anything that can be marshalled into a slice of bytes can be used.

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 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