consume

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package consume runs a JetStream pull consumer with packtrail's lifecycle: optional pinned priority group (one active consumer per partition with managed failover), bounded concurrency, panic isolation and a graceful drain on shutdown — in-flight handlers keep running under a context detached from the shutdown signal and are only cancelled when the drain budget is exhausted (I-15).

Index

Constants

View Source
const (

	// DefaultPullExpiry is the default lifetime of a pull request.
	DefaultPullExpiry = 5 * time.Second
	// DefaultAckWait is the default ack wait. Handlers send InProgress while
	// they run, so the ack wait only bounds how long a message held by a dead
	// process waits before redelivery — not how long a handler may take.
	DefaultAckWait = 5 * time.Second
)
View Source
const DefaultDrain = 30 * time.Second

DefaultDrain is the default drain budget.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, js jetstream.JetStream, cfg Config) error

Run creates (or updates) the consumer and processes messages until ctx is done, then drains.

func ShuttingDown

func ShuttingDown(ctx context.Context) <-chan struct{}

ShuttingDown returns a channel closed when the runner that called the handler starts shutting down. Handler contexts are detached from shutdown (in-flight work drains); a handler that is only *waiting* (not working) uses this to give its message back at once (F2-06).

Types

type Config

type Config struct {
	Stream   string
	Consumer jetstream.ConsumerConfig
	// Group, when set, makes the consumer a pinned priority group: only one
	// client receives messages at a time, another takes over when it stops
	// pulling.
	Group string
	// Concurrency bounds parallel handlers (<= 1: strictly serial).
	Concurrency int
	Drain       time.Duration
	// PullExpiry bounds how long a pull request lives on the server: a
	// request left behind by a stopped client can absorb a message until the
	// ack wait expires (0 = DefaultPullExpiry).
	PullExpiry time.Duration
	// KeepExisting uses an existing consumer as configured instead of
	// updating it (consumers shared by many processes, e.g. workers).
	KeepExisting bool
	// OnReady receives the consumer's effective configuration.
	OnReady func(*jetstream.ConsumerInfo)
	// Pulling is called once, when the consumer starts pulling messages.
	Pulling func()
	Logger  *slog.Logger
	Handler Handler
}

Config configures Run.

type Handler

type Handler func(ctx context.Context, msg jetstream.Msg)

Handler processes one message and must ack/nak/term it.

Jump to

Keyboard shortcuts

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