streamqueue

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

Documentation

Overview

Package streamqueue defines package-owned stream queue semantics shared by native backend adapters.

Index

Constants

View Source
const MaxBatchSize int64 = 256

MaxBatchSize bounds one read or reclaim operation.

Variables

View Source
var (
	// ErrInvalidSemanticRequest classifies invalid stream command requests.
	ErrInvalidSemanticRequest = errors.New("streamqueue: invalid semantic request")
	// ErrMalformedDelivery classifies invalid backend delivery metadata.
	ErrMalformedDelivery = errors.New("streamqueue: malformed delivery")
)

Functions

func ApplyMessageMetadata

func ApplyMessageMetadata(record *management.JobRecord, metadata *job.Metadata)

ApplyMessageMetadata copies only the public allowlist into a management record. Backend-derived source identity remains separate from OriginalID.

func MessageAge

func MessageAge(id string, now time.Time) (time.Duration, error)

MessageAge derives an entry age from a server-generated stream identifier.

func MessageMetadata

func MessageMetadata(body []byte) *job.Metadata

MessageMetadata returns validated operational metadata from the bounded job envelope. Malformed and legacy bodies have no trustworthy metadata.

Types

type AckRequest

type AckRequest struct {
	// Stream is the logical stream key.
	Stream string
	// Group is consumer-group identity.
	Group string
	// ID is backend entry identity, not application identity.
	ID string
}

AckRequest identifies one consumer-group delivery to settle.

func (AckRequest) Validate

func (r AckRequest) Validate() error

Validate checks acknowledgement identity.

type AddRequest

type AddRequest struct {
	// Stream is the logical stream key.
	Stream string
	// MaxLength is positive append capacity/count policy interpreted by the transport.
	MaxLength int64
	// Body contains mutable payload bytes without copying the backing array.
	Body []byte
}

AddRequest describes a bounded stream append.

func (AddRequest) Validate

func (r AddRequest) Validate(maxPayloadBytes int) error

Validate checks append ownership and resource bounds.

type ClaimRequest

type ClaimRequest struct {
	// Stream is the logical stream key.
	Stream string
	// Group is consumer-group identity.
	Group string
	// Consumer is read/reclaim owner identity.
	Consumer string
	// MinIdle is positive idle eligibility, not exclusive handler execution fencing.
	MinIdle time.Duration
	// Start is the opaque server reclaim scan cursor.
	Start string
	// Count bounds returned entries, not all server scan work.
	Count int64
}

ClaimRequest describes one bounded stale-delivery reclaim scan.

func (ClaimRequest) Validate

func (r ClaimRequest) Validate() error

Validate checks reclaim ownership and scan bounds.

type ClaimResult

type ClaimResult struct {
	// Next is the next server scan cursor, not a snapshot identity.
	Next string
	// Deliveries contains mutable recovered entries with transport-defined byte ownership.
	Deliveries []Delivery
}

ClaimResult contains reclaimed entries and the next bounded scan cursor.

type DeadLetterRequest

type DeadLetterRequest struct {
	// Source is the source stream to settle after destination append.
	Source string
	// Destination must identify a distinct terminal stream.
	Destination string
	// Group is consumer-group identity.
	Group string
	// Delivery holds pending source identity, body and replay lineage.
	Delivery Delivery
	// Failure holds bounded disposition without content redaction.
	Failure FailureMetadata
}

DeadLetterRequest describes an append-before-ack terminal transfer.

func (DeadLetterRequest) Validate

func (r DeadLetterRequest) Validate(maxPayloadBytes int) error

Validate checks terminal transfer identity and payload bounds.

type Delivery

type Delivery struct {
	// ID is backend entry identity, not application identity.
	ID string
	// Body contains mutable payload bytes without copying the backing array.
	Body []byte
	// Attempts counts backend deliveries, separately from local handler retries.
	Attempts int64
	// Reclaimed marks a stale pending entry recovered by this transport.
	Reclaimed bool
	// OriginalDeadLetterID identifies the first terminal record in replay lineage.
	OriginalDeadLetterID string
	// PriorDeadLetterID identifies the immediately preceding terminal record.
	PriorDeadLetterID string
	// ReplayGeneration is positive only with complete lineage; zero means no replay metadata.
	ReplayGeneration uint32
}

Delivery is the transport-neutral representation of one stream entry.

type FailureMetadata

type FailureMetadata struct {
	// Classification selects backend-neutral disposition.
	Classification management.Classification
	// Code is a bounded caller-controlled failure label; keep its content non-sensitive.
	Code string
}

FailureMetadata is the bounded disposition persisted with a failure record.

func (FailureMetadata) Validate

func (m FailureMetadata) Validate() error

Validate rejects unknown classifications and blank/oversized codes. It does not inspect or redact code content.

type GroupState

type GroupState struct {
	// Pending counts delivered group entries not acknowledged.
	Pending int64
	// Lag counts undelivered group entries; negative means unknown.
	Lag int64
	// OldestPendingID is the server identity used to derive pending age.
	OldestPendingID string
}

GroupState contains server-reported consumer-group depth components.

func (GroupState) Stats

func (s GroupState) Stats() Stats

Stats derives depth only for nonnegative lag, otherwise leaving Depth=-1. It does not validate counters or guard int64 overflow of Pending+Lag.

type ReadRequest

type ReadRequest struct {
	// Stream is the logical stream key.
	Stream string
	// Group is consumer-group identity.
	Group string
	// Consumer is read/reclaim owner identity.
	Consumer string
	// Count is the positive batch ceiling, at most MaxBatchSize.
	Count int64
	// Block is positive blocking duration; millisecond command encoding truncates fractions.
	Block time.Duration
}

ReadRequest describes one cancellation-aware consumer-group read.

func (ReadRequest) Validate

func (r ReadRequest) Validate() error

Validate checks consumer identity and command bounds.

type RequestError

type RequestError struct {
	// Command identifies the rejected operation without its input values.
	Command string
	// Field identifies the rejected field; caller construction controls label disclosure.
	Field string
	// Cause retains the validation cause for programmatic inspection.
	Cause error
}

RequestError identifies an invalid semantic field without including its potentially sensitive value.

func (*RequestError) Error

func (e *RequestError) Error() string

Error returns value-free request validation text.

func (*RequestError) Unwrap

func (e *RequestError) Unwrap() []error

Unwrap retains the stable classification and underlying cause.

type Stats

type Stats struct {
	// Depth combines pending and lag only when lag is known.
	Depth int64
	// Pending counts delivered group entries not acknowledged.
	Pending int64
	// Lag counts undelivered group entries; negative means unknown.
	Lag int64
	// LagKnown distinguishes determinate depth/lag from unsupported measurements.
	LagKnown bool
}

Stats is the common honest consumer-group depth snapshot.

type Transport

type Transport interface {
	// EnsureGroup creates or verifies a consumer group; existing group ownership is transport-defined.
	EnsureGroup(context.Context, string, string) error
	// Add appends one entry subject to native admission policy.
	Add(context.Context, AddRequest) (string, error)
	// Read returns new group entries with transport-defined byte ownership.
	Read(context.Context, ReadRequest) ([]Delivery, error)
	// Claim recovers stale pending entries; idle time is not exclusive execution fencing.
	Claim(context.Context, ClaimRequest) (ClaimResult, error)
	// Ack settles one pending entry; a lost response may leave an ambiguous outcome.
	Ack(context.Context, AckRequest) error
	// DeadLetter appends terminal metadata before acknowledging source; failures can duplicate records.
	DeadLetter(context.Context, DeadLetterRequest) error
	// GroupState returns measured group counters without inventing unsupported lag.
	GroupState(context.Context, string, string) (GroupState, error)
	// Close releases owned transport resources; this signature has no caller context.
	Close() error
}

Transport is the semantic boundary implemented by each native stream client adapter. It intentionally contains queue operations rather than a union of arbitrary datastore commands.

Jump to

Keyboard shortcuts

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