reader

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 12 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package reader reads the partitions of a topic with a PartitionReader, which groups them by primary and reads the partitions of a group together, and hands over one message at a time with an IggyConsumer.

Index

Constants

View Source
const (
	// DefaultMaxWait is the wait of a read of a reader unless its options say otherwise.
	DefaultMaxWait = 5 * time.Second
	// DefaultPrefetchMessages bounds the messages of the reads in flight and the queued batches.
	DefaultPrefetchMessages = 16_000
	// DefaultRetryInterval is the pause before a refused or failed read is sent again.
	DefaultRetryInterval = time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type IggyConsumer

type IggyConsumer struct {
	// contains filtered or unexported fields
}

IggyConsumer hands over one message at a time from a PartitionReader, as a standalone consumer or a consumer group member. Under CommitAuto with CommitAfterProcessing a message counts when the next one is asked for or at Shutdown, and in Consume once its handler succeeds. A handler that fails leaves its message uncounted and ends Consume with its error. Under CommitAfterDelivery a message counts when it is handed over, and under CommitAfterMarked only Mark counts. One caller at a time calls Next or runs Consume.

func NewIggyConsumer

func NewIggyConsumer(
	ctx context.Context,
	client iggcon.Client,
	streamId, topicId iggcon.Identifier,
	consumer iggcon.Consumer,
	options ...Option,
) (*IggyConsumer, error)

NewIggyConsumer starts the reader of a consumer, which a group member joins its group for. It takes the options of NewPartitionReader.

func (*IggyConsumer) Commit

func (c *IggyConsumer) Commit(ctx context.Context, checkpoint iggcon.Checkpoint) error

Commit stores the offset of a checkpoint that the consumer handed over, see PartitionReader.Commit.

func (*IggyConsumer) Consume

func (c *IggyConsumer) Consume(ctx context.Context, handler func(context.Context, ReceivedMessage) error) error

Consume runs handler on each message, one after another, until ctx ends, Shutdown, or the first failure of a handler or a read, which it returns.

func (*IggyConsumer) Mark

func (c *IggyConsumer) Mark(checkpoint iggcon.Checkpoint) error

Mark counts a checkpoint that the consumer handed over, see PartitionReader.Mark.

func (*IggyConsumer) Messages

Messages yields the messages until ctx ends, Shutdown, or an error, which it yields last.

func (*IggyConsumer) Next

Next returns the next message. It fails with a *ReadError for an error of a read, after which the consumer goes on.

func (*IggyConsumer) Partitions

func (c *IggyConsumer) Partitions() []uint32

Partitions are the partitions of the reader.

func (*IggyConsumer) Seek

func (c *IggyConsumer) Seek(ctx context.Context, partitionID uint32, start iggcon.PollingStrategy) error

Seek sets the next position of a partition, see PartitionReader.Seek. The messages of the partition that the consumer still holds are dropped.

func (*IggyConsumer) Shutdown

func (c *IggyConsumer) Shutdown(ctx context.Context) error

Shutdown stops a running Consume after its current handler, counts the last message under CommitAfterProcessing, and closes the reader, which stores, moves offsets back and leaves its group as its commit policy says.

type Option

type Option func(*config)

Option configures a PartitionReader.

func WithLogger

func WithLogger(logger *slog.Logger) Option

WithLogger sets the logger of the retries.

func WithPartitions

func WithPartitions(partitions ...uint32) Option

WithPartitions sets the partitions of a standalone consumer, which requires them. A consumer group reads the assignment of its member.

func WithPollOptions

func WithPollOptions(options iggcon.PollOptions) Option

WithPollOptions sets the options of each read and the commit policy, WaitPollOptions(DefaultMaxWait) by default, which stores nothing.

func WithPrefetchMessages

func WithPrefetchMessages(messages uint32) Option

WithPrefetchMessages bounds the messages of the reads in flight and the queued batches, the larger of DefaultPrefetchMessages and the count by default.

func WithRetryInterval

func WithRetryInterval(interval time.Duration) Option

WithRetryInterval sets the pause before a refused or failed read is sent again.

func WithStart

func WithStart(start iggcon.PollingStrategy) Option

WithStart sets the start of a partition without a position, NextPollingStrategy by default.

type PartitionReader

type PartitionReader struct {
	// contains filtered or unexported fields
}

PartitionReader reads the partitions of a topic in batches, with routing, prefetch and the position of each partition inside. Next returns the next batch of one partition, in offset order within one generation of the partition: from its first read, from each Seek, and from each new assignment.

With CommitManual, Commit stores the offset of a delivered checkpoint. With CommitOnRead the server stores each read, the reader reads only when Next waits, and after a read whose reply was lost it reads again by offset, without a store, the messages that the lost read stored, and delivers them first. A partition that leaves the assignment still hands over the reads that the server stored for it. Close moves the offset of each partition with undelivered batches back to its last delivered message. With CommitAuto the reader counts each batch as the policy says, or each Mark, and stores the latest counted position at its interval or event, before a rebalance takes a partition away, and in Close.

func NewPartitionReader

func NewPartitionReader(
	ctx context.Context,
	client iggcon.Client,
	streamId, topicId iggcon.Identifier,
	consumer iggcon.Consumer,
	options ...Option,
) (*PartitionReader, error)

NewPartitionReader starts a reader. A consumer group reader joins its group first.

func (*PartitionReader) Close

func (r *PartitionReader) Close(ctx context.Context) error

Close stops the reader and waits for its reads, which it lets end. With CommitAuto it counts the last batch under CommitAfterProcessing and stores the latest counted position of each partition. With CommitOnRead it first stores the offset of each seek that waited for one of those reads, then moves the offset of each partition with undelivered batches back to its last delivered message. A group reader then leaves its group. It returns the first failed store or leave. A later Close waits for the first one and returns its result.

func (*PartitionReader) Commit

func (r *PartitionReader) Commit(ctx context.Context, checkpoint iggcon.Checkpoint) error

Commit stores the offset of a checkpoint that this reader delivered. A checkpoint of an older generation, or at or below the last commit of its generation, stores nothing. It fails with ierror.ErrInvalidCommand under CommitOnRead and for a partition that the reader does not read.

func (*PartitionReader) Mark

func (r *PartitionReader) Mark(checkpoint iggcon.Checkpoint) error

Mark counts a checkpoint that this reader delivered, under CommitAuto. With CommitAfterMarked only marks count. It fails with ierror.ErrInvalidCommand without CommitAuto, and for a checkpoint of another generation.

func (*PartitionReader) Next

Next returns the next batch of one partition, never empty. A cancelled call leaves its batch in the reader. It fails with a *ReadError for an error of a read.

func (*PartitionReader) Partitions

func (r *PartitionReader) Partitions() []uint32

Partitions are the partitions that the reader reads now.

func (*PartitionReader) Seek

func (r *PartitionReader) Seek(ctx context.Context, partitionID uint32, start iggcon.PollingStrategy) error

Seek sets the next read position of a partition and starts a new generation of it. It drops the queued batches of the partition and resumes a stopped one. Under CommitOnRead, a seek to an offset stores the offset before it once the read in flight ended, so the next read of the server starts there.

type ReadError

type ReadError struct {
	// PartitionID is the partition of the error, or nil for an error of the whole reader.
	PartitionID *uint32
	Err         error
	// Skip is, for a message that does not decode, the continuation after it.
	// The partition stops until a Seek, to Skip to step over the message.
	Skip *iggcon.PollingStrategy
}

ReadError is an error of a read. The reader stays usable after it and retries by itself.

func (*ReadError) Error

func (e *ReadError) Error() string

func (*ReadError) Unwrap

func (e *ReadError) Unwrap() error

type ReceivedMessage

type ReceivedMessage struct {
	PartitionID uint32
	Message     iggcon.IggyMessage
	// Checkpoint is the position after the message, for a commit or a mark.
	Checkpoint iggcon.Checkpoint
	// EndsBatch marks the last message of the batch that the reader read.
	EndsBatch bool
}

ReceivedMessage is one message that an IggyConsumer handed over.

Jump to

Keyboard shortcuts

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