nats

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Client

func Client(s bandmaster.Service) *nats.Conn

Client returns the underlying `nats.Conn` of the given service.

It assumes that the service is ready; i.e. it might return nil if it's actually not.

NOTE: This will panic if `s` is not a `nats.Service`.

func Config

func Config(s bandmaster.Service) *nats.Options

Config returns the underlying `nats.Options` of the given service.

NOTE: This will panic if `s` is not a `nats.Service`.

func New

func New(opts *nats.Options) bandmaster.Service

New creates a new NATS service using the provided `nats.Options`. You may use the helpers for environment-based configuration to get a pre-configured `nats.Options` with sane defaults.

It doesn't open any connection nor does it do any kind of I/O; i.e. it cannot fail.

Types

type Env

type Env struct {
	Addrs            []string      `envconfig:"ADDRS" default:"nats://localhost:4222"`
	AllowReconnect   bool          `envconfig:"ALLOW_RECONNECT" default:"true"`
	MaxReconnect     int           `envconfig:"MAX_RECONNECT" default:"60"`
	ReconnectWait    time.Duration `envconfig:"RECONNECT_WAIT" default:"2s"`
	Timeout          time.Duration `envconfig:"TIMEOUT" default:"2s"`
	PingInterval     time.Duration `envconfig:"PING_INTERVAL" default:"2m"`
	MaxPingsOut      int           `envconfig:"MAX_PINGS_OUT" default:"2"`
	SubChanLen       int           `envconfig:"SUBCHAN_LEN" default:"8192"`
	ReconnectBufSize int           `envconfig:"RECONNECT_BUFSIZE" default:"8388608"` // 8MB
	DialerTimeout    time.Duration `envconfig:"DIALER_TIMEOUT" default:"2s"`
}

Env can be used to configure a NATS session via the environment.

It comes with sane defaults for a local development set-up.

func NewEnv

func NewEnv(prefix string) (*Env, error)

NewEnv parses the environment and returns a new `Env` structure.

`prefix` defines the prefix for the environment keys, e.g. with a 'XX' prefix, 'REPLICAS' would become 'XX_REPLICAS'.

func (*Env) Config

func (e *Env) Config() *nats.Options

Config returns a `nats.Options` using the values from the environment.

type Service

type Service struct {
	*bandmaster.ServiceBase // "inheritance"
	// contains filtered or unexported fields
}

Service implements a NATS service based on the 'nats-io/nats' package.

func (*Service) Start

Start opens a connection and PINGs the server: if everything goes smoothly, the service is marked as 'started'; otherwise, an error is returned.

Start is used by BandMaster's internal machinery, it shouldn't ever be called directly by the end-user of the service.

func (*Service) Stop

func (s *Service) Stop(ctx context.Context) error

Stop closes the underlying `nats.Conn`: if everything goes smoothly, the service is marked as 'stopped'; otherwise, an error is returned.

Stop is used by BandMaster's internal machinery, it shouldn't ever be called directly by the end-user of the service.

Jump to

Keyboard shortcuts

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