message

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package message defines the outbox data model.

Index

Constants

View Source
const TableName = "outbox_messages"

TableName is the fixed outbox table name. The schema is configurable at runtime; the table name itself is constant so it stays in lockstep with the embedded migration.

View Source
const TombstoneTableName = "outbox_tombstones"

TombstoneTableName holds the compact outcomes of removed dead/discarded rows (same schema as TableName).

Variables

View Source
var (
	// ErrEmptyTopic is returned when a message has no topic.
	ErrEmptyTopic = errors.New("outbox: message topic is empty")
	// ErrNilPayload is returned when a message payload is nil.
	ErrNilPayload = errors.New("outbox: message payload is nil")
)

Functions

This section is empty.

Types

type Message

type Message struct {
	ID           string            // uuid; empty -> generated by the database; dedupe key on enqueue
	Topic        string            // transport destination (queue/topic/subject)
	PartitionKey string            // ordering key (used by ordered mode)
	Payload      []byte            // opaque bytes; encoding is the codec's job
	Headers      map[string]string // transport metadata
	ContentType  string            // codec hint, e.g. "application/json"
	MessageType  string            // logical message type
	MaxAttempts  *int              // per-message override; nil -> relay default

	// Populated when read back by the relay.
	Status        Status
	Attempts      int
	LeaseToken    string // unique per claim, including reclaims by the same instance
	LockedBy      string
	LockedUntil   *time.Time
	NextAttemptAt time.Time
	LastError     string
	CreatedAt     time.Time
	PublishedAt   *time.Time
	FinishedAt    *time.Time // published, discarded, or dead
}

Message is a single outbox row.

On enqueue, the caller sets Topic and Payload (required) and optionally ID, PartitionKey, Headers, ContentType, MessageType, MaxAttempts. The remaining fields are populated by the relay when a message is read back; Enqueue ignores them, so NextAttemptAt cannot schedule delivery: a new row is due immediately.

func (Message) Validate

func (m Message) Validate() error

Validate reports whether the message is well-formed for enqueue.

type Status

type Status string

Status is the lifecycle state of an outbox message.

const (
	StatusPending    Status = "pending"
	StatusProcessing Status = "processing"
	StatusPublished  Status = "published"
	StatusDead       Status = "dead"
	StatusDiscarded  Status = "discarded"
)

Jump to

Keyboard shortcuts

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