stream

package module
v0.0.0-...-7fb72bf Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2022 License: MIT Imports: 10 Imported by: 4

README

Stream Library

This is a shared library to make writing and reading to an event stream easier. For now this event stream is Kafka. This library aims to remove boilerplate for using both Kafka and OpenTracing and then get out of the way as fast as possible.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventID

type EventID string

type Reader

type Reader interface {
	// RegisterHandler adds an event handler that will perform some action
	// when an event with the given ID is received.  Must be called before
	// calling Listen.
	RegisterHandler(event EventID, handler StreamEventHandler) error

	// Listen will listen for incoming events and route them internally.
	// This is a blocking call.
	Listen(ctx context.Context) error
}

func NewKafkaStreamReader

func NewKafkaStreamReader(topic string, brokers []string, groupId string) Reader

type Serializer

type Serializer interface {
	Serialize(buf io.Writer) error
}

Serializer is something that can Serialize to a writer, such as an Avro object

type StreamEventHandler

type StreamEventHandler func(ctx context.Context, data []byte) error

type Writer

type Writer interface {
	// Close gives underlying resources a chance to flush and close gracefully
	Close() error

	// Write will write a payload to the stream with the given event ID using
	// the given key to send to the correct partition.
	//
	// Note that the key is a Kafka primary key which will dictate the partition
	// and order guarantees for the event.  For example, the User ID should be used
	// on all events that have to do with a particular User.
	Write(ctx context.Context, key []byte, eventID EventID, payload Serializer) error
}

func NewKafkaStreamWriter

func NewKafkaStreamWriter(topic string, brokers []string) Writer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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