broker

package
v0.0.0-...-b02c517 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Broker

type Broker[T Value] interface {
	// Init initializes the provider itself.
	Init(...Option)
	// String returns the implementation name.
	String() string
	// Publish receives an event and sends it to its corresponding queue.
	Publish(*Event[T], ...PublishOption) error
	// Subscribe returns an event subscriber.
	Subscribe(...SubscribeOption) (Subscriber[T], error)
}

Broker is a generic interface for asynchronous events transport.

func NewMemory

func NewMemory[T Value](opts ...Option) Broker[T]

type Event

type Event[T Value] struct {
	// Kind names the event type.
	Kind Kind
	// Time is when this event is emitted. If zero, the current time will be used.
	Time time.Time
	// Queue is the group of watchers this event will be dispatched to.
	Queue string
	// Values curries a series of values to be consumed by subscribers.
	Values []T
	// Metadata curries optional values.
	Metadata metadata.MD
}

Event is a generic event.

type Kind

type Kind uint8
const (
	Unknown Kind = iota
	Create
	Delete
	Update
)

type Option

type Option func(*Options)

func Address

func Address(addr string) Option

type Options

type Options struct {
	// Address specifies the broker address.
	Address string
}

type PublishOption

type PublishOption func(*PublishOptions)

func PublishContext

func PublishContext(c context.Context) PublishOption

type PublishOptions

type PublishOptions struct {
	Context context.Context
}

type SubscribeOption

type SubscribeOption func(*SubscribeOptions)

func Queue

func Queue(name string) SubscribeOption

type SubscribeOptions

type SubscribeOptions struct {
	// Queue specifies a queue to subscribe events from.
	Queue string
}

type Subscriber

type Subscriber[T Value] interface {
	// Chan returns a event channel.
	Chan() <-chan *Event[T]
	// Next returns the next event.
	Next() (*Event[T], error)
	// Unsubscribe cancels the subscription.
	Unsubscribe()
}

Subscriber is a generic event subscriber.

type Value

type Value interface {
	String() string
}

Jump to

Keyboard shortcuts

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