Help us shape the future of Go! Take the 2026 Go Developer Survey

stream

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package stream reads the messages of a RabbitMQ stream without moving anything: over the stream protocol with an unnamed consumer (no offset stored, no single-active-consumer group joined), or over AMQP 0-9-1 with an x-stream-offset consumer. Neither path ever stores an offset.

Index

Constants

View Source
const MaxRead = 200

MaxRead is the hard ceiling of one read (read_max's ceiling).

Variables

View Source
var (
	ErrNeedsStreamProtocol = errors.New("stream: this needs the stream protocol: set stream_url on the profile")
	ErrNoTunnel            = errors.New("stream: the stream protocol cannot go through an ssh tunnel; set amqp_url to read streams over AMQP")
	ErrNoSuchStream        = errors.New("stream: no such stream")
	ErrAccess              = errors.New("stream: access refused")
	ErrTimeout             = errors.New("stream: timeout")
	ErrFailed              = errors.New("stream: request failed")
	ErrMax                 = errors.New("stream: max must be 1 or more")
)

Errors. Their text never holds a host, a user or a secret.

Functions

This section is empty.

Types

type DialFunc

type DialFunc func(ctx context.Context, network, addr string) (net.Conn, error)

DialFunc opens a connection (an SSH tunnel's Dial).

type From

type From struct {
	// Kind is first, last, offset or timestamp.
	Kind   string
	Offset int64
	Time   time.Time
}

From is where a read starts.

func ParseFrom

func ParseFrom(s string) (From, error)

ParseFrom parses "first", "last", an offset ("1200") or an RFC 3339 timestamp ("2026-10-19T10:40:00Z").

func (From) String

func (f From) String() string

type Reader

type Reader interface {
	// Read returns at most max messages from from. It ends at max, when no
	// message came for a short while (the end of the stream), or at ctx's
	// end, whichever comes first: an empty stream or an offset past its end
	// returns no message, never blocks. Each message carries its offset in
	// the header x-stream-offset.
	Read(ctx context.Context, vhost, stream string, from From, max int) ([]msgmask.Message, error)
	// Stats returns the first offset and the first offset of the last
	// committed chunk; -1, -1 for an empty stream. Stream protocol only.
	Stats(ctx context.Context, vhost, stream string) (first, last int64, err error)
	// QueryOffset reads the offset stored by a named consumer. Stream
	// protocol only.
	QueryOffset(ctx context.Context, vhost, stream, consumerRef string) (int64, error)
}

Reader reads a stream.

func NewAMQP

func NewAMQP(host string, port int, tlsCfg *tls.Config, user string, secret []byte, dial DialFunc) Reader

NewAMQP returns a reader over AMQP 0-9-1: a consumer with x-stream-offset, prefetch max, manual acks (on a stream an ack only returns credit) and a cancel after max. Stats and QueryOffset return ErrNeedsStreamProtocol.

func NewStreamProto

func NewStreamProto(host string, port int, tlsCfg *tls.Config, user string, secret []byte, dial DialFunc) Reader

NewStreamProto returns a reader over the stream protocol. The client library dials TCP itself: with dial set (an SSH tunnel) every call returns ErrNoTunnel.

Jump to

Keyboard shortcuts

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