queue

package
v0.34.1 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package queue implements the persistent failed-message (dead-letter) queue on top of the sqlitedb KV store.

Each queued message is stored as its own row under the key

<queue name> || 0x00 || <8-byte big-endian time> || <8-byte big-endian seq>

so that enqueueing is O(1) (no read-modify-write of an aggregate blob) and fetching never destroys data: FetchFailedMsgs only reads, and the caller removes each row with Dequeue after the message has been processed. A crash mid-cycle therefore re-delivers instead of losing messages (at-least-once). Older releases stored the whole queue as a single CBOR list under the bare queue name; FetchFailedMsgs migrates such rows to the per-message layout on first encounter.

Index

Constants

View Source
const MaxQueueAge = 30 * 24 * time.Hour

MaxQueueAge caps how long a failed message is retried before being dropped at fetch.

Variables

View Source
var ErrQueueing = errors.New("problem with persistent queue")

Functions

func Dequeue added in v0.34.0

func Dequeue(ctx context.Context, eDB *sqlitedb.Edb, key []byte)

Dequeue removes a processed row returned by FetchFailedMsgs. Call it only after the outcome is durable (delivered, or re-queued as a fresh row): a crash before Dequeue re-delivers rather than loses. The delete survives ctx cancel so a shutdown mid-drain doesn't duplicate the row next run.

func StoreFailedMsgs

func StoreFailedMsgs(ctx context.Context, eDB *sqlitedb.Edb, key []byte, g msgtypes.Message) error

StoreFailedMsgs appends g to the queue as its own row, so cost is independent of queue depth. QueuedAt is stamped on first failure to anchor MaxQueueAge.

Types

type Queued added in v0.34.0

type Queued struct {
	Key []byte
	Msg msgtypes.Message
}

Queued couples a fetched message with the row key it was read from so the caller can Dequeue exactly that row once the message has been processed.

func FetchFailedMsgs

func FetchFailedMsgs(ctx context.Context, eDB *sqlitedb.Edb, queueKey []byte) []Queued

FetchFailedMsgs returns the failed messages queued under queueKey, oldest first, without removing them: rows stay in the database until the caller confirms processing via Dequeue, so a crash mid-resend re-delivers instead of losing messages.

Messages older than MaxQueueAge are dropped (their rows deleted) here. Legacy aggregate-blob queues written by older releases are transparently split into per-message rows on first encounter.

If any of the operations fail, the function logs an error and returns whatever could be read.

Jump to

Keyboard shortcuts

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