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 ¶
- func DecodeDeadLetter(encoded []byte, visibility management.PayloadVisibility) (management.JobRecord, error)
- type Option
- func WithAddr(addr string) Option
- func WithChannel(channel string) Option
- func WithConnectTimeout(timeout time.Duration) Option
- func WithDeadLetter(topic string, maxAttempts uint16) Option
- func WithLogLevel(lvl nsq.LogLevel) Option
- func WithLogger(l queue.Logger) Option
- func WithMaxInFlight(num int) Option
- func WithRequestTimeout(timeout time.Duration) Option
- func WithRunFunc(fn func(context.Context, core.TaskMessage) error) Option
- func WithTopic(topic string) Option
- func WithTouchInterval(interval time.Duration) Option
- type OptionFunc
- type Options
- type Worker
- func (*Worker) BackendName() string
- func (w *Worker) Queue(job core.TaskMessage) error
- func (w *Worker) QueueName() string
- func (w *Worker) Request() (core.TaskMessage, error)
- func (w *Worker) Run(ctx context.Context, task core.TaskMessage) error
- func (w *Worker) Shutdown() error
- func (w *Worker) Stats() *nsq.ConsumerStats
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 WithConnectTimeout ¶
WithConnectTimeout bounds NSQ producer and consumer connection attempts.
func WithDeadLetter ¶
WithDeadLetter configures the package-owned terminal topic and bounded NSQ delivery-attempt policy.
func WithLogLevel ¶
WithLogLevel set custom nsq log level
func WithMaxInFlight ¶
WithMaxInFlight Maximum number of messages to allow in flight (concurrency knob)
func WithRequestTimeout ¶
WithRequestTimeout sets how long Request waits for an NSQ message.
func WithRunFunc ¶
WithRunFunc setup the run func of queue
func WithTouchInterval ¶
WithTouchInterval sets how often an in-flight NSQ message is touched.
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 NewWorkerE ¶
NewWorkerE creates a worker and returns configuration errors.
func (*Worker) BackendName ¶
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) Request ¶
func (w *Worker) Request() (core.TaskMessage, error)
Request fetch new task from queue
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.