Documentation
¶
Overview ¶
Package queue provides a small lifecycle-aware in-process work queue.
It is deliberately an application primitive, not a pretend durable broker: messages in memory are lost when the process exits. Use the outbox package (or a real broker) when a job must survive a crash.
Index ¶
- type Handler
- type Message
- type Options
- type Queue
- func (q *Queue) Enqueue(ctx context.Context, body []byte) (string, error)
- func (q *Queue) Name() string
- func (q *Queue) OnReady(ctx context.Context) error
- func (q *Queue) OnShutdown(ctx context.Context) error
- func (q *Queue) Start(parent context.Context) error
- func (q *Queue) Stop(ctx context.Context) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
Handler processes a message. Returning an error retries it until MaxAttempts is reached.
type Message ¶
Message is one queued payload. Attempts starts at one when a worker begins processing it.
type Options ¶
type Options struct {
Name string
Workers int
Buffer int
MaxAttempts int
RetryDelay time.Duration
OnDeadLetter func(context.Context, Message, error)
}
Options configures a Queue.
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue is safe for concurrent producers and consumers.
func New ¶
New constructs a queue. It starts when registered with a lifecycle registry and OnReady runs, or when Start is called directly.
func (*Queue) Enqueue ¶
Enqueue adds a payload, returning when it has entered the queue buffer. Enqueue is valid before Start, which makes boot-time producers convenient.
func (*Queue) OnShutdown ¶
OnShutdown stops accepting work and drains messages already buffered.