client

package
v0.4.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// The default client
	Default = New()
	// The default server list
	Servers = []string{"http://127.0.0.1:8081"}
	// The default number of retries
	Retries = 1
)

Functions

func Publish

func Publish(topic string, payload []byte) error

Publish via the default Client

func Subscribe

func Subscribe(topic string) (<-chan []byte, error)

Subscribe via the default Client

func Unsubscribe

func Unsubscribe(ch <-chan []byte) error

Unsubscribe via the default Client

Types

type Client

type Client interface {
	Close() error
	Publish(topic string, payload []byte) error
	Subscribe(topic string) (<-chan []byte, error)
	Unsubscribe(<-chan []byte) error
}

Client is the interface provided by this package

func New

func New(opts ...Option) Client

New returns a new Client

type Option

type Option func(o *Options)

func WithResolver

func WithResolver(r Resolver) Option

WithResolver sets the resolver used to get the server list

func WithRetries

func WithRetries(i int) Option

WithRetries sets the number of retry attempts

func WithSelector

func WithSelector(s Selector) Option

WithSelector sets the server selector used by the client

func WithServers

func WithServers(addrs ...string) Option

WithServers sets the servers used by the client

type Options

type Options struct {
	// Number of retry attempts
	Retries int
	// Resolver
	Resolver Resolver
	// Server list
	Servers []string
	// Selector
	Selector Selector
}

type Resolver

type Resolver interface {
	Resolve(name string) ([]string, error)
}

Resolver resolves a name to a list of servers

type Selector

type Selector interface {
	Get(topic string) ([]string, error)
	Set(servers ...string) error
}

Selector provides a server list to publish/subscribe to

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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