embed

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package embed starts and supervises NATS JetStream servers in-process.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cluster

type Cluster struct {
	Nodes []*Node
	// contains filtered or unexported fields
}

func StartCluster

func StartCluster(cfg ClusterConfig) (*Cluster, error)

StartCluster spins up an in-process cluster of Size nodes on loopback with random free ports. All nodes share cfg.Name. Returns once all nodes accept connections; call WaitMetaLeader via the stream package before creating streams.

func (*Cluster) ClientURLs

func (c *Cluster) ClientURLs() string

ClientURLs returns a comma-separated URL list suitable for nats.Connect.

func (*Cluster) Shutdown

func (c *Cluster) Shutdown()

Shutdown stops all nodes. Does not wait between shutdowns — callers doing graceful rolling shutdowns should call Node.Shutdown() individually with appropriate gaps.

func (*Cluster) ShutdownNode

func (c *Cluster) ShutdownNode(i int)

ShutdownNode stops a single node; useful for failover testing.

func (*Cluster) WaitReady

func (c *Cluster) WaitReady(timeout time.Duration) error

WaitReady blocks until the JetStream meta-leader is elected and the meta group has discovered all peers. Required before creating streams with Replicas > 1. Returns an error if the deadline passes first.

type ClusterConfig

type ClusterConfig struct {
	// Size is the number of nodes (must be >= 1; 3 for HA quorum).
	Size int
	// Name is the cluster name shared by all nodes.
	Name string
	// BaseDir is the parent dir for per-node StoreDir. If empty, uses os.MkdirTemp.
	BaseDir string
	// ReadyWait is the per-node timeout waiting for connections.
	ReadyWait time.Duration
}

type Node

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

func StartNode

func StartNode(cfg NodeConfig) (*Node, error)

func (*Node) ClientURL

func (n *Node) ClientURL() string

func (*Node) Server

func (n *Node) Server() *natsserver.Server

func (*Node) Shutdown

func (n *Node) Shutdown()

type NodeConfig

type NodeConfig struct {
	ServerName string
	Host       string
	Port       int
	StoreDir   string
	ReadyWait  time.Duration
}

Jump to

Keyboard shortcuts

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