natsconn

package
v1.134.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 6 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	URI      string
	Token    string
	Name     string
	Replicas int // JetStream KV replica count; defaults to 1
}

Config holds the connection parameters for NATS. Decoupled from protobuf config so this package can be imported externally.

type ReloadableConnection

type ReloadableConnection struct {
	*nats.Conn
	Replicas int // JetStream KV replica count
	// contains filtered or unexported fields
}

ReloadableConnection wraps a NATS connection and provides reconnection notifications via a pub/sub fan-out to subscribers.

func New

func New(cfg *Config, logger log.Logger) (*ReloadableConnection, func(), error)

New creates a ReloadableConnection with automatic reconnection handling. Returns (nil, cleanup, nil) when cfg is nil or URI is empty (NATS is optional). The cleanup function drains the NATS connection on shutdown.

func (*ReloadableConnection) Broadcast

func (rc *ReloadableConnection) Broadcast()

Broadcast notifies all subscribers of a reconnection event. Non-blocking: if a subscriber's channel is full, the signal is dropped. Nil-receiver safe.

func (*ReloadableConnection) Subscribe

func (rc *ReloadableConnection) Subscribe(ctx context.Context) <-chan struct{}

Subscribe registers for reconnection notifications. The returned channel receives a signal each time the NATS connection is re-established. The subscription is automatically removed when ctx is cancelled. Nil-receiver safe: returns a closed channel.

Jump to

Keyboard shortcuts

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