nats

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 15 Imported by: ? modules, 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 Action

type Action int
const (
	ActionNak Action = iota
	ActionNakWithDelay
	ActionTerm
)

type Client

type Client struct {
	*nats.Conn

	JetStream jetstream.JetStream
	// contains filtered or unexported fields
}

func NewClient

func NewClient(opts *Opts) (*Client, error)

func (*Client) CreateOrUpdateStream

func (c *Client) CreateOrUpdateStream(ctx context.Context, s *Stream) (jetstream.Stream, error)

func (*Client) Publish

func (c *Client) Publish(ctx context.Context, subject *Subject, message proto.Message) error

func (*Client) Start

func (c *Client) Start(ctx context.Context) error

func (*Client) WithLogger

func (c *Client) WithLogger(logger *slog.Logger) *Client

type Message

type Message[T proto.Message] struct {
	Timestamp time.Time
	Headers   map[string][]string
	Payload   T
	// contains filtered or unexported fields
}

type Opts

type Opts struct {
	Host           string        `long:"host" env:"HOST" required:"true"`
	Port           int           `long:"port" env:"PORT" default:"4222"`
	TotalWait      time.Duration `long:"total-wait" env:"TOTAL_WAIT" default:"10m"`
	ReconnectDelay time.Duration `long:"reconnect-delay" env:"RECONNECT_DELAY" default:"1s"`
}

type ProcessingError

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

func NakError

func NakError(err error) *ProcessingError

func NakWithDelayError

func NakWithDelayError(err error, delay time.Duration) *ProcessingError

func TermError

func TermError(err error) *ProcessingError

func (*ProcessingError) Error

func (e *ProcessingError) Error() string

func (*ProcessingError) Unwrap

func (e *ProcessingError) Unwrap() error

type Processor

type Processor[T proto.Message] struct {
	// contains filtered or unexported fields
}

func NewProcessor

func NewProcessor[T proto.Message](client *Client, config *ProcessorConfig, processorFunc ProcessorFunc[T], opts ...ProcessorOpt[T]) *Processor[T]

func (*Processor[T]) Close

func (p *Processor[T]) Close()

func (*Processor[T]) HealthCheck

func (p *Processor[T]) HealthCheck(ctx context.Context) error

HealthCheck checks the health of this routine.

func (*Processor[T]) Start

func (p *Processor[T]) Start(ctx context.Context) error

func (*Processor[T]) WithLogger

func (p *Processor[T]) WithLogger(logger *slog.Logger) *Processor[T]

func (*Processor[T]) WithMetrics

func (p *Processor[T]) WithMetrics() *Processor[T]

type ProcessorConfig

type ProcessorConfig struct {
	Subjects             []*Subject
	ConsumerName         string
	MaxConsecutiveErrors int
	BatchSize            int
	FetchTimeout         time.Duration
	AckWait              time.Duration
	BackoffSeconds       int
	// DeliverFromLatest configures the consumer to start from the latest offset on creation.
	// This only takes effect when the consumer is first created; existing consumers retain their cursor.
	DeliverFromLatest bool
}

type ProcessorFunc

type ProcessorFunc[T proto.Message] func(ctx context.Context, message *Message[T]) error

type ProcessorOpt

type ProcessorOpt[T proto.Message] func(*Processor[T])

func WithGroupKey

func WithGroupKey[T proto.Message](keyFunc func(*Message[T]) (string, error)) ProcessorOpt[T]

WithGroupKey groups messages by the returned key. Messages within a group are processed serially in the order they were received; groups are processed in parallel.

type Stream

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

func NewStream

func NewStream(streamOptions *natspb.StreamOptions) *Stream

func (*Stream) Name

func (s *Stream) Name() string

Name returns the stream's name on the wire, which is its dotted proto name with the dots replaced by underscores, as in malonaz_test_library_v1_shelf.

func (*Stream) Subject

func (s *Stream) Subject(suffix string) *Subject

type Subject

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

func (*Subject) Name

func (s *Subject) Name() string

Name returns the subject's name on the wire, so that a test can select on it without reconstructing the mangling Stream.Name describes.

Directories

Path Synopsis
Package teststore provides a buffered store of the messages a system under test publishes to NATS, so that tests can assert on side effects the RPCs triggering them do not wait for.
Package teststore provides a buffered store of the messages a system under test publishes to NATS, so that tests can assert on side effects the RPCs triggering them do not wait for.

Jump to

Keyboard shortcuts

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