Help us shape the future of Go! Take the 2026 Go Developer Survey

nats

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package nats adapts Core NATS queue subscriptions, not JetStream. Delivery is transient without handler acknowledgements or durable replay. Construction opens and subscribes an owned connection; Shutdown drains/closes it. Request decoding is bounded, but broker acceptance is not proof of handler completion.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*options)

Option for queue system

func WithAddr

func WithAddr(addrs ...string) Option

WithAddr setup the addr of NATS

func WithConnectTimeout

func WithConnectTimeout(timeout time.Duration) Option

WithConnectTimeout bounds the initial NATS connection attempt.

func WithLogger

func WithLogger(l queue.Logger) Option

WithLogger set custom logger

func WithQueue

func WithQueue(queue string) Option

WithQueue setup the queue of NATS

func WithRequestTimeout

func WithRequestTimeout(timeout time.Duration) Option

WithRequestTimeout sets how long Request waits for a NATS message.

func WithRunFunc

func WithRunFunc(fn func(context.Context, core.TaskMessage) error) Option

WithRunFunc setup the run func of queue

func WithSubj

func WithSubj(subj string) Option

WithSubj setup the subject of NATS

type Worker

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

Worker owns a Core NATS connection and transient subscription.

func NewWorker

func NewWorker(opts ...Option) *Worker

NewWorker constructs the worker and panics on an error from NewWorkerE.

func NewWorkerE

func NewWorkerE(opts ...Option) (*Worker, error)

NewWorkerE creates a worker and returns connection and subscription errors.

func (*Worker) BackendName

func (*Worker) BackendName() string

BackendName identifies Core NATS in lifecycle events.

func (*Worker) Queue

func (w *Worker) Queue(job core.TaskMessage) error

Queue publishes encoded bytes through the Core NATS client without a durable confirmation or handler acknowledgement. A closed worker rejects admission.

func (*Worker) QueueName

func (w *Worker) QueueName() string

QueueName returns the configured NATS subject.

func (*Worker) Request

func (w *Worker) Request() (core.TaskMessage, error)

Request a new task

func (*Worker) Run

func (w *Worker) Run(ctx context.Context, task core.TaskMessage) error

Run synchronously invokes the configured handler; it must honor ctx.

func (*Worker) Shutdown

func (w *Worker) Shutdown() error

Shutdown worker

Jump to

Keyboard shortcuts

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