Documentation
¶
Overview ¶
Package nats is a NATS connection as a dependency: a configuration section, a connection that never gives up (reconnecting with jitter, no buffering while disconnected, transitions logged), a status probe. The SDK's own event bus connects through Connect too.
The platform's events travel on the bus of the SDK block (BACKPLANE_NATS_*); this is for a NATS of the service's own — one backplane does not see:
type Config struct {
config.Backplane `json:"backplane"`
Realtime nats.Config `json:"realtime"` // CALLS_REALTIME_URL, ...
}
rt := deps.NewDependency(root, nats.New(cfg.Realtime), deps.Name("realtime"))
js, err := jetstream.New(rt.Get())
Index ¶
Constants ¶
View Source
const ( DefaultReconnectWait = 2 * time.Second DefaultReconnectJitter = time.Second )
Defaults of Options.
Variables ¶
View Source
var ( // ErrNoURL: the section has no URL. ErrNoURL = errors.New("nats: url is required") // ErrDisconnected is what the probe reports while the connection is // down. ErrDisconnected = errors.New("nats: not connected") )
Errors.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// URL is one server or a comma-separated list.
URL config.Secret `json:"url,omitempty"`
// Creds is the content of a .creds file (user JWT and seed).
Creds config.Secret `json:"creds,omitempty"`
TLS config.TLS `json:"tls"`
}
Config is the connection's section.
type Options ¶
type Options struct {
// Name of the client as the server lists it.
Name string
Log *xlog.Logger
// OnStatus is told every change of connectivity.
OnStatus func(connected bool)
// OnClosed runs once the connection is closed for good.
OnClosed func()
// Pause between reconnection attempts; zero is the default.
ReconnectWait, ReconnectJitter time.Duration
}
Options of Connect beyond the section.
Click to show internal directories.
Click to hide internal directories.