nats

package module
v0.0.0-...-b87209e Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package nats provides a NATS registry using broadcast queries

Index

Constants

View Source
const Name = "nats"

Name provides the name of this registry.

Variables

View Source
var (
	DefaultAddresses  = []string{"nats://localhost:4222"}
	DefaultQueryTopic = "micro.registry.nats.query"
	DefaultWatchTopic = "micro.registry.nats.watch"
)

Defaults.

Functions

func ProvideRegistryNATS

func ProvideRegistryNATS(
	name types.ServiceName,
	version types.ServiceVersion,
	datas types.ConfigData,
	logger log.Logger,
	opts ...registry.Option,
) (registry.Type, error)

ProvideRegistryNATS creates a new NATS registry.

func WithAddress

func WithAddress(n ...string) registry.Option

WithAddress sets the NATS server addresses.

func WithQueryTopic

func WithQueryTopic(n string) registry.Option

WithQueryTopic sets the NATS query topic.

func WithQuorum

func WithQuorum(n int) registry.Option

WithQuorum sets the NATS quorum.

func WithSecure

func WithSecure(n bool) registry.Option

WithSecure defines if we want a secure connection to nats.

func WithTLSConfig

func WithTLSConfig(n *tls.Config) registry.Option

WithTLSConfig defines the TLS config to use for the secure connection.

func WithWatchTopic

func WithWatchTopic(n string) registry.Option

WithWatchTopic sets the NATS watch topic.

Types

type Config

type Config struct {
	registry.Config `yaml:",inline"`

	Addresses []string    `json:"addresses,omitempty" yaml:"addresses,omitempty"`
	Secure    bool        `json:"secure,omitempty" yaml:"secure,omitempty"`
	TLSConfig *tls.Config `json:"-" yaml:"-"`

	Quorum int `json:"quorum,omitempty" yaml:"quorum,omitempty"`

	QueryTopic string `json:"queryTopic,omitempty" yaml:"queryTopic,omitempty"`
	WatchTopic string `json:"watchTopic,omitempty" yaml:"watchTopic,omitempty"`
}

Config provides configuration for the NATS registry.

func NewConfig

func NewConfig(
	serviceName types.ServiceName,
	datas types.ConfigData,
	opts ...registry.Option,
) (Config, error)

NewConfig creates a new config object.

func (*Config) ApplyOptions

func (c *Config) ApplyOptions(opts ...registry.Option)

ApplyOptions applies a set of options to the config.

type RegistryNATS

type RegistryNATS struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

RegistryNATS implements the registry interface. It runs a NATS service registry.

func New

func New(serviceName string, serviceVersion string, cfg Config, log log.Logger) *RegistryNATS

New creates a new NATS registry. This functions should rarely be called manually. To create a new registry use ProvideRegistryNATS.

func (*RegistryNATS) Deregister

func (n *RegistryNATS) Deregister(
	service *registry.Service, _ ...registry.DeregisterOption,
) error

Deregister deregisters a service within the registry.

func (*RegistryNATS) GetService

func (n *RegistryNATS) GetService(s string, _ ...registry.GetOption) ([]*registry.Service, error)

GetService returns a service from the registry.

func (*RegistryNATS) ListServices

func (n *RegistryNATS) ListServices(_ ...registry.ListOption) ([]*registry.Service, error)

ListServices lists services within the registry.

func (*RegistryNATS) NodeID

func (n *RegistryNATS) NodeID() string

NodeID returns the ID of this service node in the registry.

func (*RegistryNATS) Register

func (n *RegistryNATS) Register(s *registry.Service, _ ...registry.RegisterOption) error

Register registers a service within the registry.

func (*RegistryNATS) ServiceName

func (n *RegistryNATS) ServiceName() string

ServiceName returns the configured name of this service.

func (*RegistryNATS) ServiceVersion

func (n *RegistryNATS) ServiceVersion() string

ServiceVersion returns the configured version of this service.

func (*RegistryNATS) Start

func (n *RegistryNATS) Start() error

Start the registry.

func (*RegistryNATS) Stop

func (n *RegistryNATS) Stop(_ context.Context) error

Stop the registry.

func (*RegistryNATS) String

func (n *RegistryNATS) String() string

String returns the plugin name.

func (*RegistryNATS) Type

func (n *RegistryNATS) Type() string

Type returns the component type.

func (*RegistryNATS) Watch

func (n *RegistryNATS) Watch(opts ...registry.WatchOption) (registry.Watcher, error)

Watch returns a registry.Watcher which you can watch on.

Jump to

Keyboard shortcuts

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