lib

package
Version: v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

A service discovery library for use with Olric distributed cache. Provides Nats.io service discovery for use with a standalone, embedded, or clustered v2 nats-server.

Index

Constants

View Source
const (
	DefaultProvider = `nats`

	// The default nats subject to use when communicating
	// with other available nodes
	DefaultDiscoverySubject = `olric-service-discovery`

	// How long we should wait to collect as many results as possible
	DefaultDiscoveryTimeout = 50 * time.Millisecond
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Optional provider name: default "nats"
	Provider string

	// The nats://host:port of a nats server
	Url string

	// Optionally specify a list of nats://host:port
	// endpoints in a cluster for redundancy
	Servers []string

	// Override the default nats subject channel to use
	// for all service discovery communication in this olric cluster.
	// Customizing allows for multiple olric clusters to communicate
	// over a single nats server cluster
	Subject string

	// Override the max time to wait for a response from nodes,
	// when discovering peers.
	// If your nodes have a large amount of latency between each
	// other, you may want to adjust this higher than DefaultDiscoveryTimeout
	// to wait longer for replies
	DiscoveryTimeout time.Duration

	// The payload to use when delivering messages to peers
	Payload Payload
}

Configuration options to use when creating a client connection to a nats server, and sending service discovery payloads

type MapConfig

type MapConfig = map[string]interface{}

MapConfig is a map-based configuration that can be passed to SetConfig

type NatsDiscovery

type NatsDiscovery struct {
	Config *Config
	// contains filtered or unexported fields
}

NatsDiscovery is the ServiceDiscovery client interface

func (*NatsDiscovery) Close

func (n *NatsDiscovery) Close() error

Close stops underlying goroutines, if there is any. It should be a blocking call.

func (*NatsDiscovery) Deregister

func (n *NatsDiscovery) Deregister() error

Deregister this node from a service discovery directory.

func (*NatsDiscovery) DiscoverPeers

func (n *NatsDiscovery) DiscoverPeers() ([]string, error)

DiscoverPeers returns a list of known Olric nodes.

func (*NatsDiscovery) Initialize

func (n *NatsDiscovery) Initialize() error

Initialize the plugin: registers some internal data structures, clients etc.

func (*NatsDiscovery) Register

func (n *NatsDiscovery) Register() error

Register this node to a service discovery directory.

func (*NatsDiscovery) SetConfig

func (n *NatsDiscovery) SetConfig(c MapConfig) error

SetConfig registers plugin configuration

func (*NatsDiscovery) SetLogger

func (n *NatsDiscovery) SetLogger(l *log.Logger)

SetLogger sets a custom logger instance

type Payload

type Payload struct {
	// The host name representing this client node
	Host string
	// The port number of the client
	Port int
	// An optional client name for logging
	ClientName string
}

Payload contains the user-configurable information about the client that should be made available to the rest of the peers during service discovery

func (*Payload) Address

func (p *Payload) Address() string

Address returns the host:port string

Source Files

Jump to

Keyboard shortcuts

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