natsconn

package
v1.89.8 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

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
}

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
	// 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