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

nsq

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: 17 Imported by: 0

Documentation

Overview

Package nsq adapts NSQ topic/channel delivery with manual FIN/REQ settlement. Terminal handling publishes to a separate topic before FIN; a failure or crash between those operations can duplicate terminal records. Construction prepares a producer and Request opens the consumer; Shutdown releases both.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeDeadLetter

func DecodeDeadLetter(
	encoded []byte,
	visibility management.PayloadVisibility,
) (management.JobRecord, error)

DecodeDeadLetter converts one package-owned NSQ terminal envelope into the backend-neutral management record without exposing NSQ client types.

Types

type Option

type Option interface {
	// Apply mutates construction settings synchronously.
	Apply(*Options)
}

Option configures NSQ producer/consumer policy at construction.

func WithAddr

func WithAddr(addr string) Option

WithAddr setup the addr of NSQ

func WithChannel

func WithChannel(channel string) Option

WithChannel setup the channel of NSQ

func WithConnectTimeout

func WithConnectTimeout(timeout time.Duration) Option

WithConnectTimeout bounds NSQ producer and consumer connection attempts.

func WithDeadLetter

func WithDeadLetter(topic string, maxAttempts uint16) Option

WithDeadLetter configures the package-owned terminal topic and bounded NSQ delivery-attempt policy.

func WithLogLevel

func WithLogLevel(lvl nsq.LogLevel) Option

WithLogLevel set custom nsq log level

func WithLogger

func WithLogger(l queue.Logger) Option

WithLogger set custom logger

func WithMaxInFlight

func WithMaxInFlight(num int) Option

WithMaxInFlight Maximum number of messages to allow in flight (concurrency knob)

func WithRequestTimeout

func WithRequestTimeout(timeout time.Duration) Option

WithRequestTimeout sets how long Request waits for an NSQ message.

func WithRunFunc

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

WithRunFunc setup the run func of queue

func WithTopic

func WithTopic(topic string) Option

WithTopic setup the topic of NSQ

func WithTouchInterval

func WithTouchInterval(interval time.Duration) Option

WithTouchInterval sets how often an in-flight NSQ message is touched.

type OptionFunc

type OptionFunc func(*Options)

OptionFunc is a function that configures a queue.

func (OptionFunc) Apply

func (f OptionFunc) Apply(option *Options)

Apply calls f(option)

type Options

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

Options retains private NSQ construction settings; use the With functions. Options are applied in order without nil-option normalization.

type Worker

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

Worker owns an NSQ producer and lazily opened manual-settlement consumer.

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 configuration errors.

func (*Worker) BackendName

func (*Worker) BackendName() string

BackendName identifies NSQ in lifecycle events.

func (*Worker) Queue

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

Queue publishes encoded bytes to the configured NSQ topic through the producer. It does not wait for a handler or FIN; closed workers reject publication.

func (*Worker) QueueName

func (w *Worker) QueueName() string

QueueName returns the configured NSQ topic.

func (*Worker) Request

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

Request fetch new task from queue

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

func (*Worker) Stats

func (w *Worker) Stats() *nsq.ConsumerStats

Stats returns native consumer counters, or nil before consumer startup. These are transport statistics, not a transactional application-work snapshot.

Jump to

Keyboard shortcuts

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