pubsub

package
v0.0.0-...-96862d9 Latest Latest
Warning

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

Go to latest
Published: May 16, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package pubsub provides the needed primitives for a Publish-Subscribe system

Package pubsub provides the needed primitives for a Publish-Subscribe system

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNoSuchTopicError

func IsNoSuchTopicError(e error) bool

func IsNotImplementedError

func IsNotImplementedError(e error) bool

Types

type ErrType

type ErrType string
const (
	NoSuchTopic    ErrType = "NO_SUCH_TOPIC_ERROR"
	NotImplemented ErrType = "NOT_IMPLEMENTED_ERROR"
	Unknown        ErrType = "UNKNOWN_ERROR"
)

type Event

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

Event data structure

func NewEvent

func NewEvent(kind EventType, configPath string) *Event

NewEvent returns a pointer to Event type kind EventType, the kind of Event configPath string, the config path

func (*Event) ConfigPath

func (ev *Event) ConfigPath() string

ConfigPath returns the path to

func (*Event) CreatedAt

func (ev *Event) CreatedAt() time.Time

CreatedAt returns the timestamp when the Event was created

func (*Event) Kind

func (ev *Event) Kind() EventType

Kind returns the EventType

func (*Event) String

func (ev *Event) String() string

String returns a new string with the Event information

type EventType

type EventType uint8

EventType is type of configuration change Event

const (
	// ConfigCreated EventType indicates that a new config has been created
	ConfigCreated EventType = iota
	// ConfigUpdated EventType indicates that the config has changed
	ConfigUpdated
	// ConfigDeleted EventType indicates that the config has been deleted
	ConfigDeleted
)

func (EventType) String

func (t EventType) String() string

String returns the string version of EventType

type InMemory

type InMemory struct {
	sync.Mutex
	// contains filtered or unexported fields
}

InMemory is the data structure implementing the PubSub interface

func (*InMemory) CreateTopic

func (im *InMemory) CreateTopic(topic string) error

CreateTopic creates a new topic from string

func (*InMemory) DeleteTopic

func (im *InMemory) DeleteTopic(topic string) error

DeleteTopic deletes a given topic

func (*InMemory) Publish

func (im *InMemory) Publish(topic string, ev *Event) error

Publish injects a new *Event into a topic

func (*InMemory) Subscribe

func (im *InMemory) Subscribe(topic string) (*Subscription, error)

Subscribe adds a new subscription to a topic, returns the newly created Subscription object, or NoSuchTopicError if the topic is not created yet

func (*InMemory) TopicExists

func (im *InMemory) TopicExists(topic string) bool

TopicExists checks whether or not a topic exists

func (*InMemory) UnSubscribe

func (im *InMemory) UnSubscribe(topic string, sID string) error

UnSubscribe removes a subscription from a topic

type Kind

type Kind string

Kind is the KV kind

const INMEMORY Kind = "in-memory"

INMEMORY is an in-memory PubSub implementation

func PubSubFromName

func PubSubFromName(name string) (Kind, error)

PubSubFromName returns the PubSub Kind from the provided name It will return a NotImplementedError otherwise

type NoSuchTopicError

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

func NewNoSuchTopicError

func NewNoSuchTopicError(topic string) NoSuchTopicError

func (NoSuchTopicError) Error

func (e NoSuchTopicError) Error() string

type NotImplementedError

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

func NewNotImplementedError

func NewNotImplementedError(impl string) NotImplementedError

func (NotImplementedError) Error

func (e NotImplementedError) Error() string

type PubSub

type PubSub interface {
	CreateTopic(topic string) error
	DeleteTopic(topic string) error
	TopicExists(topic string) bool
	Publish(topic string, ev *Event) error
	Subscribe(topic string) (*Subscription, error)
	UnSubscribe(topic string, sID string) error
}

PubSub provides an API for a Publish-Subscribe system

func NewPubSub

func NewPubSub(kind Kind) (PubSub, error)

NewPubSub returns an implementation of the PubSub interface

type Subscription

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

Subscription type

func NewSubscription

func NewSubscription() *Subscription

NewSubscription creates a new Subscription

func (*Subscription) Channel

func (s *Subscription) Channel() chan *Event

Channel returns the subscription channel

func (*Subscription) ID

func (s *Subscription) ID() string

ID returns the subscription id

Jump to

Keyboard shortcuts

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