topics

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2023 License: BSD-3-Clause Imports: 4 Imported by: 1

Documentation

Index

Constants

View Source
const DefaultTimeout = 15 * time.Second

Variables

View Source
var (
	// TODO: move to dedicated errors package
	ErrTopicNotFound = errors.New("topic with specified name does not exist")
)

Functions

This section is empty.

Types

type Cache

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

Cache manages topics on behalf of the user, looking up topicIDs by name and cacheing them to prevent multiple remote requests. The cache should also wrap an Ensign client but the cache uses the topic management functionality of the client, so an independent interface is added to make testing simpler.

func NewCache

func NewCache(client Client) *Cache

func (*Cache) Clear

func (t *Cache) Clear()

Clear the topic cache resetting any internal cached state and refetching topic info.

func (*Cache) Ensure

func (t *Cache) Ensure(topic string) (topicID string, err error)

Ensure the topic exists by first performing a check if the topic exists and if it doesn't, then creating the topic. The topicID of the created topic is cached to prevent repeated calls to CreateTopic that will fail after the first call (topic already exists error).

func (*Cache) Exists

func (t *Cache) Exists(topic string) (exists bool, err error)

Exists checks if the topic exists, first by checking the cache and if the topic is not in the cache by performing an RPC call to ensign to check if the topic exists.

func (*Cache) Get

func (t *Cache) Get(topic string) (topicID string, err error)

Get returns a topicID from a topic; if the topic is not in the cache; an RPC call to ensign is made to get and store the topic ID.

func (*Cache) Length

func (t *Cache) Length() int

Length returns the number of items in the cache

type Client

type Client interface {
	TopicExists(context.Context, string) (bool, error)
	TopicID(context.Context, string) (string, error)
	CreateTopic(context.Context, string) (string, error)
}

Jump to

Keyboard shortcuts

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