natsclient

package
v2.12.3 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 10 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package natsclient configures how a NATS client identifies itself from command-line flags, and reports when its connection cannot recover.

Index

Constants

View Source
const DefaultAuthFailureGrace = 5 * time.Minute

DefaultAuthFailureGrace outlasts the kubelet's refresh of a mounted Secret, which by default takes up to its one-minute sync plus a one-minute cache TTL.

Variables

This section is empty.

Functions

This section is empty.

Types

type Flags

type Flags struct {
	Creds        string
	Nkey         string
	TokenFile    string
	User         string
	PasswordFile string
	Name         string
	InboxPrefix  string
	// AuthFailureGrace is how long the server may refuse the credential before
	// Liveness fails. Zero means DefaultAuthFailureGrace.
	AuthFailureGrace time.Duration
	// contains filtered or unexported fields
}

Flags is how a NATS client identifies itself. Register binds each field to a flag; a field set beforehand becomes that flag's default.

func (Flags) Options

func (f Flags) Options() ([]nats.Option, error)

Options builds the client options, keeping secrets out of process arguments. Credentials, tokens, and passwords are reread on connect; a new bare nkey requires a restart.

func (*Flags) Register

func (f *Flags) Register(fs *flag.FlagSet, prefix string)

Register defines the flags on fs as -<prefix>-creds, -<prefix>-nkey and so on, such as -nats-creds for the prefix "nats".

type Liveness

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

Liveness reports when a connection can no longer recover on its own: once it is closed, or once the server has kept refusing its credential for longer than the grace period without a connect in between. Reconnecting for any other reason stays healthy, so a NATS rollout does not restart the client.

IgnoreAuthErrorAbort keeps a client retrying a refused credential so it can pick up a rotated Secret. A credential still refused after the grace will not be replaced by a refresh, and a restart at least surfaces it.

func NewLiveness

func NewLiveness(grace time.Duration) *Liveness

NewLiveness fails once the credential has been refused for longer than grace. Zero means DefaultAuthFailureGrace.

func (*Liveness) Check

func (l *Liveness) Check(_ *http.Request) error

Check is a controller-runtime healthz.Checker.

func (*Liveness) Option

func (l *Liveness) Option() nats.Option

Option records every refusal and reconnect, rather than only those a probe happens to sample. It wraps any error and reconnect handlers set by the options before it, so append it last.

func (*Liveness) Watch

func (l *Liveness) Watch(conn *nats.Conn)

Watch sets the connection Check reports on, which must have been opened with Option.

Jump to

Keyboard shortcuts

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